Xplore SFDC is a blog containing information regarding the salesforce and apex code scenarios. You will find resourceful content which will help you in day to day coding journey
Thursday, April 20, 2023
Free Salesforce Certification Vouchers
Monday, April 17, 2023
How To Avoid Recursion in Apex Trigger
Recursion is the process of executing the same Trigger multiple times to update the record again and again due to automation. There may be chances we might hit the Salesforce Governor Limit due to Recursive Trigger.
To avoid these kind of situation we can use public class static variable.
Thursday, April 13, 2023
Polymorphism in Apex Programming with Example
Polymorphism is a concept in object-oriented programming where a single method or function can be used to perform different operations based on the type of object that it is called on. In Apex, polymorphism can be achieved using interfaces, abstract classes, and virtual methods. Here's an example of polymorphism in Apex using interfaces:
In the above example, we define an interface called Shape with a method called draw(). We then define two classes, Circle and Rectangle, that implement the Shape interface and provide their own implementation of the draw() method.
Finally, we create two objects of type Shape, one of type Circle and one of type Rectangle. When we call the draw() method on each of these objects, the appropriate implementation of the draw() method is called based on the type of the object, demonstrating polymorphism.
Let me know your thoughts in the comment section!!
Interfaces in Apex Programming with Example
In programming, an interface is a collection of abstract methods and constants that can be implemented by a class. Here are some uses of interfaces in programming:
Abstraction: Interfaces allow you to define a contract or a set of rules that must be followed by any class that implements the interface. This helps to separate the implementation details from the interface, making the code more modular and easier to maintain.
Polymorphism: Interfaces allow you to achieve polymorphism in your code. Since any class that implements the interface must provide an implementation for all of the methods in the interface, you can create objects of different classes that implement the same interface and treat them as if they were the same type.
Multiple Inheritance: In some programming languages, a class can only inherit from one parent class. However, a class can implement multiple interfaces, allowing it to inherit from multiple sources. This makes it easier to create complex class hierarchies without having to rely on multiple inheritance.
In this example, we define an interface called Interest that has one method called calculatePaymentAmount(). Any class that implements the Interest interface must provide an implementation for the calculatePaymentAmount() method.
Here's an example of a class that implements the Interest interface:
In this example, the HomeLoanPayment class implements the Interest interface by providing an implementation for the calculatePaymentAmount() method. This method calculates the payment amount for a Home Loan.
By using an interface in this way, we can define a common set of methods that must be implemented by any class that implements the interface. This allows us to write more flexible and reusable code.
Where do we use Interfaces in Apex
Batch Apex: Developer needs to implement the Database.Batchable interface. Thats why we need to write three methods namely, Start, Execute and Finish.
Queueable Apex: In this scenario, developer needs to implement Queueable interface and implement the Execute method.
Let me know your thoughts in the comment section!!
Saturday, April 8, 2023
Static Variables and Static Methods in Apex
Static variables are variables that belong to an overall class, not a particular object of a class. Think of a static variable to be like a global variable – its value is shared across your entire org. Any particular object’s properties or values are completely irrelevant when using static. When a class containing static variables is first referenced, the static variables are initialized. The initialization process occurs only once per execution context, regardless of how many times the class is referenced.
This example illustrates static vs. non-static variables
Static methods, similarly, are methods that act globally and not in the context of a particular object of a class. Being global, static methods only have access to its provided inputs and other static (global) variables.
This example illustrates static vs. non-static methods
Mostly Viewed
-
Hello Friends, Many developers are facing the issue of setting up ANT Migration Tool for Salesforce with Proxy Settings. Today, I h...
-
Top Salesforce Interview Questions Are you worried about clearing your interview? If yes, then definitely I am going to help you in gett...
-
Hello All, Please leave your email id in the comment box or mail at sfdev52@gmail.com T he voucher will sent to your email id. Free Salesfor...