Category: best practice

Best Practices for Lightning Web Components

Lightning Web Components (LWC) is a new programming model for building modern, scalable, and high-performance web applications on the Salesforce platform. LWC is based on modern web standards and provides a developer-friendly experience for building reusable components that can be shared across an organization. In this blog post, I will explore some best practices for building lightning web components and how to leverage the LWC programming model to build efficient and maintainable applications. You can read – Apex Programming Best Practices Salesforce Flow Best Practices Use Modules for Reusibility One of the best practices for building Lightning Web Components...

Read More

10 Apex Programming Best Practices

Apex is a strongly-typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Lightning Platform. It is a key component of the Lightning Platform and allows developers to build robust business logic and integrations. There are a number of best practices that Apex developers should follow to ensure their code is efficient, maintainable, and scalable. Below are ten tips for writing high-quality Apex code. You can read – Lightning Web Component Best Practices Salesforce Flow Best Practices 10 Apex Programming Best Practices Use of "sObject" Data Type Use the “sObject” data type when...

Read More

JavaScript Tips for Visualforce Developers

When I started my career 10 years back, I was first introduced to Server Side Programming. I started developing applications using Embedded C/C++. Slowly I shifted my focus towards Client Side Programming. It always motivates me if I see the end-result of my development immediately. That is how I started digging into Client Side Programmings. I always love this below quote from one of my favorite programmers – Eric ElliottIn my initial days I still remember, it was really difficult to learn JavaScript. To me, Javascript was more like a “side” language which can help implementing those functionalities which can’t be delivered by server side programming – such as DOM manipulations, browser events and things like that. So for me sending data between server and client was always a GET and POST.But I realized the power of JavaScript very soon. Trust me, with JavaScript, you can do so many things you can’t even imagine. You can not only do Client Side operations, you can perform server-side logics as well. Yes, you hear it correctly. JavaScript for Server Side Programming. With the “node.js”  you can perform server-side computations as well. But there is even more. We can now build Isomorphic applications as well. With an Isomorphic application, your initial request from the web browser will be handled by the server, but after that, any subsequent requests will be handled by...

Read More

APEX TRIGGER DESIGN PATTERN

This post is part of the series – Design Pattern in ApexI know it was discussed number of times earlier about Apex Trigger Design Pattern. Below are few excellent posts -http://gokubi.com/archives/two-interesting-ways-to-architect-apex-triggershttp://www.embracingthecloud.com/2010/07/08/ASimpleTriggerTemplateForSalesforce.aspxI have learned a lot from the above two posts by Steve Andersen and Mike Leach.But the post by Abhinav Gupta really inspires me a lot and I am going to explain the pattern/template here with few use cases.The motivations for this design pattern are -Write Trigger with minimum codeFollow Salesforce Best Practice – One Trigger per objectFollow another Salesforce Best Practice – Move all code from Trigger to Apex Classes – Handler ClassesAbility to add and order multiple handlers for the same trigger event.Easy to maintain code base.Here is the Apex Trigger template – MyTriggers (Again inspired by Abhinav Gupta)Now using the above template, below is the account trigger handler – AccountTriggerHandlerAnd finally the trigger – AccountTriggerNow the trigger code is very neat and clean. At the same time all our operations against trigger events are moved to handler class.So now let’s consider few use cases -Use Case 1 -While inserting new accounts, if the Account Rating is marked as ‘Hot’, then mark those accounts as Active and make the Customer Priority as ‘Medium’.Implementation -To implement the above requirement, what we need to do is simply add the functionality in AccountTriggerHandler.AccountBeforeInsertHandler class. No changes in Apex trigger code is required.Here is the updated AccountTriggerHandlerUse...

Read More

Importance of Equals and Hashcode in Apex

Recently while doing code review, I found that all developers should have fundamental understanding of “Why we should implement always Equals and Hashcode in Apex?”In this post, I am going to share my knowledge with few examples to understand the importance of Equals and Hashcode in Apex.Apex provides you an option to define an equal method in your custom types. This Equals method along with Hashcode is must when you are going to use your custom types in Sets and as Map keys. I would recommend to make this approach (Implementation of Equals and Hashcode) as best practice. Equality operator (==) is going to use the Equals operator if it is defined.Why we need this Equals method?Let me start with one example to show you the problem if Equals method is not implemented. Below is the custom type I am having -Now below is the test class to compare two instances of MyCustomType. Both the instances of MyCustomType is having myField value set to 10. So my expectation is that when I will compare both the instances, they should return true. Let’s see what will happen. Below is the test class.But unfortunately, below is what you will get -You see our test class is failing. Do you know the reason? Let me tell you the reason. The reason for this comparison to fail is that I don’t have the Equals method in...

Read More
Loading