Salesforce Apex Code Repository

Salesforce provides couple of developer related objects which are very useful when a developer wants to fetch the metadata information of apex class, components, pages, triggers, code coverage using apex code. There are lot of scenarios where we can utilize these objects :- To search any referenced fields and objects inside apex classes,pages & triggers….

What is Dynamic Apex in Salesforce and how to use it ?

Dynamic apex enables developers to create more flexible applications by providing them with the ability to “Access sObject and field describe information”, “Write Dynamic SOQL Queries”, “Write Dynamic SOSL Queries” and “Dynamic DML”. It consists of several components such as schema describe, dynamic SOQL, dynamic SOSL, and dynamic DML. 1) Access sObject and field describe…

How to write test class for Batch Apex in Salesforce ?

We should always test batch class with good amount of data (minimum 200 records) in our test class. Here is the example of batch apex testing. In below code, we are updating name of all accounts with “Updated” keyword in the last of account name. Batch Class: global class AccountUpdate implements Database.Batchable { global Database.QueryLocator…

How do we write a Batch Class in APEX and schedule it to run?

Scenario We need to look at all Accounts and update the related Contacts description with Rating field from respective Account. e.g. “Account rating is Cold” Why Batch Apex ? Batch Apex is used to process high volume of records and it allows us to run their code on a specific time. In batch APEX there is the…

How to write APEX Triggers and What are the best practices?

Apex triggers allows you to perform some actions when any record is created, updated, deleted or undeleted in Salesforce. What can we do using triggers? A trigger can perform following actions: Insert, Update, Delete records. Update fields from child to parent and vice-versa. Send Emails to record owner, external user, contact & lead etc. Call…

How can we handle Approval Process using APEX?

Approval process is an automated process which is used to submit, approve and reject records in Salesforce. It specifies the steps necessary for a record to be approved and who must approve it at each step. We can configure approval process from Salesforce, and then use APEX to submit, approve or reject the record. Automatic Submission of Record for Approval…

How can we Insert, Update and Delete a record in a Visualforce Page ?

We can do simple Insert, Update and Delete in a Visualforce Page with out using any APEX code. If you want extend the standard methods, you will need to write an extension to the Standard Controller or create a Custom Controller. Simple INSERT, UPDATE, DELETE in Visualforce page: We can insert, update and delete records by  using…