Posts

Showing posts from June, 2016

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...