Posts

Get Picklist Values Using Dynamic Apex

Image
  The picklist field name and object are the two parameters that the code snippet below requires. We can read either the Picklist label or the value based on these two inputs. String objectName = 'Account'; String fieldName ='Industry'; Schema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ; Schema.DescribeSObjectResult r = s.getDescribe() ; Map<String,Schema.SObjectField> fields = r.fields.getMap() ; Schema.DescribeFieldResult fieldResult = fields.get(fieldName).getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ System.debug(pickListVal.getLabel() +' ---- '+pickListVal.getValue()); }  

Use Of addFields in ApexPages.StandardController

The add fields method helps developers specify fields for the standard controller to query in Visualforce pages. public AccountController(ApexPages.StandardController stdController){             this.controller = stdController;             List<String> fieldNamesList = new List<String>{Type,Industry};             stdController.addFields( fieldNamesList );             // stdController.addFields(new List<String>{'Name', 'TaxExemption__c', ' Industry '}); } Reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_addFields.htm

Lock Records Using Apex in Salesforce

Locking Statements In Apex, you can use FOR UPDATE to lock sObject records while they’re being updated to prevent race conditions and other thread safety problems. Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE]; Locking Consideration When records are locked by a client, that client can modify the record's field values in the database within the same transaction. Other clients must wait until the transaction is completed and the records are no longer locked before they can update the same records. However, other clients can still query the locked records. If a record is already locked by another client, a process will wait for a maximum of 10 seconds for the lock to be released before acquiring a new lock. If the wait exceeds 10 seconds, a QueryException is thrown. Similarly, if a record is locked by another client and the lock is not released within 10 seconds, a DmlException is thrown. If a client tries to modify a locked record, the update can succeed if the lock ...

Web-to-Case In Salesforce

Image
Creating a Web-to-Case form in Salesforce enables you to automatically convert customer inquiries submitted through your website into cases within your Salesforce. Turn On and Customize Web-to-Case Generate and Test Your Web-to-Case Form To test the Web-to-Case form, add the line <input type="hidden" name="debug" value="1"> to the code. This line redirects you to a debugging page when you submit the form. Don’t forget to remove it before publishing the Web-to-Case page on your website. Web-to-Case Limits 5,000 cases in a 24-hour period. When you reach the 24-hour limit, additional requests are stored in a pending request queue that contains both Web-to-Case and Web-to-Lead requests Unsupported Content Types Web-to-Case forms don’t support the following content types: Attachments Rich text area (RTA) fields—If you use these fields on your forms, any information entered in them is saved as plain text when the case is created. Multipart/form-data—Cases ...

Web-to-Lead In Salesforce

Image
Creating a Web-to-Lead form in Salesforce allows you to capture lead information directly from your website and automatically create leads within your Salesforce instance Generate a new HTML by going to Setup > App Setup > Customization > Leads > Web-to-Lead. Generate Leads from Your Website for Your Sales Teams We can have multiple web-to-lead forms for various websites or landing pages and can be used to send leads to Salesforce. Please note that using the Web-to-Lead form you can automatically generate up to 500 new leads a day. Some of the Lead Sources available in Salesforce Web Phone Inquiry Partner Referral Purchased List Other Employee Referral Twitter External Referral Partner Public Relations Trade Show Word of mouth Here are the steps to follow  Click on "Create Web-to-Lead Form" Once you fill in the details, Click on "Generate" Here's a simple example of what the HTML code for the Web-to-Lead form might look like: <form action="ht...

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