Category: dynamic apex

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

Dynamic Apex – Playing with CRUD and FLS

Security is one of the important things in today’s world. And when we talk about cloud, Security is the top most priority items. No doubt. Salesforce is not an exception and they are also considering Security really seriously.In Salesforce, we have different types of Security controls – starting from org level security to object level, followed by record level and field level. This post focuses on methods for controlling data at the object and field level.As always I always believe explaining concept with examples is the best and effective way. Today also I will do the same thing.For this post, I have prepared a small object called Book and below is the detail -Important Note -In Visualforce, when you use any sObject or sObject field, the platform will enforce CRUD and FLS automatically. If the user is not having FLS to a field, Salesforce will automatically remove the field from the Visualforce page. For example, apex:inputField tag will be rendered as read-only for those fields having FLS set as read-only. But the exception here are the tags apex:inputText, apex:inputTextArea. Using these tags tells Visualforce to not treat them as sObject field, thus platform will not automatically enforce FLS for those  fields. Apex Code to check CRUD manually:Requirement:Write a Visualforce page with controller behind which should display all Books present in the org in the form of Picklist. When we will execute...

Read More

Dynamic Apex – Sky is The Limit – Explained with Example

Today I am going to explain Dynamic Apex with examples. Dynamic Apex will help developer to create more flexible and robust application because with the help of Dynamic Apex, developer can access the sObject and field describe information, access Salesforce application information. Another great help is that with Dynamic Apex, developer can now write dynamic SOQL, SOSL and DML statements. So basically with dynamic apex, you have the magic wand in your hand.So without any further delay, let’s start the power of magic wand.Basics of Apex Describe:In order to get information about sObjects in Salesforce, you have two options – either use tokens or use describeSObjects Schema methods.Apex provides two data structures and a method for fetching information about sObjects and fields. They are listed below -Token – This is a lightweight, serializable reference to an sObject or a field that is validated at run time. Since they are lightweight, using them make your code faster and more efficient.The describeSObjects method – This method from the Schema class will perform the describe on sObject Types.Describe result – This is basically the object of  type Schema.DescribeSObjectResult which holds the result i.e. contains all the describe properties for the sObject or field. These objects are not serializable and validated always at runtime. Let’s get into more details before we jump into the examples -Schema Describe -Schema Describe is a way to programmatically...

Read More