Posts

Dynamic DML in Salesforce

Dynamic DML (Data Manipulation Language) in Salesforce refers to the ability to perform insert, update, upsert, delete, and undelete operations on records dynamically at runtime. This is particularly useful when you need to work with records whose types or quantities are determined dynamically, based on user input or other runtime conditions. Salesforce provides several ways to perform dynamic DML operations, primarily through Apex, the programming language used on the Salesforce platform. Here's an overview of how dynamic DML operations can be achieved in Salesforce: Dynamic DML Operations in Apex: In Apex, you can use dynamic DML statements to perform DML operations on records dynamically. This involves constructing DML statements as strings and then executing them using methods like Database.insert(), Database.update(), Database.upsert(), Database.delete(), or Database.undelete(). Example // Define a list of sObjects to perform DML on List<SObject> recordsToInsertOrUpdate...

Salesforce Query Languages - SOQL & SOSL

In Salesforce, both SOQL (Salesforce Object Query Language) and SOSL (Salesforce Object Search Language) are query languages used to retrieve data from the Salesforce platform, but they serve different purposes and have distinct syntaxes. SOQL (Salesforce Object Query Language) : SOQL is a query language used to retrieve records from a single object or related objects in Salesforce. It's similar to SQL (Structured Query Language) and is tailored specifically for querying Salesforce data. Key features of SOQL include: SELECT Statement: Used to retrieve specific fields from records. Filters and Conditions: WHERE clause allows filtering records based on specified conditions. Relationship Queries: Allows querying related objects using relationship fields. Aggregate Functions: Supports aggregate functions like SUM(), AVG(), MAX(), MIN(), and COUNT(). Ordering and Sorting: ORDER BY clause enables sorting results based on specified fields. Example of a SOQL query: SELECT Id, Name, Accou...

Dynamic Apex in Salesforce

Dynamic Apex in Salesforce refers to the ability to construct and execute code dynamically at runtime, rather than having it defined statically at compile time. This feature allows developers to build more flexible and adaptable solutions that can respond to changing requirements or conditions during program execution. Dynamic Apex enables developers to create more flexible applications by providing them with the ability to: Access sObject and field describe information- Metadata information about sObject and field properties includes details about operations supported by sObject types (such as create or undelete), name and label of sObjects, fields and child objects. Field information contains details like default value presence, calculated field status, and field type Apex provides two data structures and a method for sObject and field describe information: Token —a lightweight, serializable reference to an sObject or a field that is validated at compile time. This is used for token...

Add a Lightning application within a Visualforce page in Salesforce

  <!-- create a lightning app with global access that extends lightning outApp-->   YourLightningComponent.app <aura:application access="GLOBAL" extends="ltng:outApp">        <aura: dependency resource="lightning: button"/>   </aura: application>   <apex:page >     <apex:includeLightning />          <div id="lightningContainer"></div>     <script>         $Lightning.use("c:YourApp", function() {             $Lightning.createComponent(                 "c:YourLightningComponent",                 {},                 "lightningContainer",                 function(cmp) {                   ...

Dynamic SOQL (Salesforce Object Query Language) and SOSL (Salesforce Object Search Language)

Dynamic SOQL (Salesforce Object Query Language) and SOSL (Salesforce Object Search Language) are powerful tools in the Salesforce ecosystem that allow developers to construct queries and search statements dynamically based on runtime conditions. This flexibility enables developers to build more dynamic and adaptable solutions. Here's an overview of dynamic SOQL and SOSL: Dynamic SOQL: Dynamic SOQL allows you to construct queries at runtime using string manipulation techniques. This is particularly useful when you don't know the structure of the query until the application is running. Here's a basic example of dynamic SOQL in Apex: String query = 'SELECT Id, Name FROM Account'; // You can add conditions dynamically based on runtime logic if(someCondition) {     query += ' WHERE CreatedDate > TODAY'; } List<Account> accounts = Database.query(query); Dynamic SOSL: Dynamic SOSL allows you to construct search queries dynamically. SOSL is used to search...

Salesforce MIXED_DML_OPERATION

The MIXED_DML_OPERATION error in Salesforce occurs when you attempt to perform a DML (Data Manipulation Language) operation on setup objects (such as User, Profile, UserRole, Group, etc.) within the same transaction as DML operations on regular sObjects (standard or custom objects).  This restriction is in place to maintain the integrity and security of Salesforce data because setup objects control system-wide settings and configurations that could impact multiple users and processes. Here's how you can handle the MIXED_DML_OPERATION error: Separate Setup and Non-Setup DML Operations : Split your DML operations into separate transactions, with one transaction handling DML operations on regular sObjects and another transaction handling DML operations on setup objects. public void handleMixedDML() {     // Perform DML operations on regular sObjects     List<Account> accountsToUpdate = [SELECT Id, Name FROM Account LIMIT 10];     // Perform DML oper...

Pagination in Visualforce using StandardSetController

Image
The StandardSetController is a controller class that enables you to create a Visualforce page to showcase a list of records. It has built-in capabilities to handle pagination, thus simplifying displaying extensive data sets on a Visualforce page. Here are some key features and functionalities of StandardSetController: Pagination : StandardSetController automatically handles pagination, allowing you to display a subset of records on each page. It provides methods for navigating between pages, such as first(), previous(), next(), and last(). Sorting and Filtering : StandardSetController allows you to specify sorting and filtering criteria for the records displayed on the Visualforce page. You can define sorting order and filter conditions using the setSortOrder() and setFilterId() methods. Record Navigation : You can easily navigate to the first, last, previous, or next page of records using methods provided by StandardSetController. This simplifies the implementation of navigation contr...