Posts

Apex Triggers in Salesforce

Image
In Salesforce, a trigger is a piece of Apex code that executes before or after specific data manipulation events occur, such as inserting, updating, deleting, or undeleting records. Triggers enable you to perform custom actions or validations when these events take place on Salesforce records. Refer to the below links for more details - Get Started with Apex Triggers Apex Triggers Define Apex Triggers Here are some key points about triggers in Salesforce: Execution Context: Triggers execute in response to specific database events and run in the Salesforce environment. Supported Events : Triggers can be defined to execute before or after specific events, including insert, update, delete, undelete, and upsert. Object-Specific: Triggers are associated with specific Salesforce objects, such as Accounts, Contacts, Opportunities, etc. Each trigger operates on records of its associated object type. Apex Language: Triggers are written in Apex, Salesforce's proprietary programming langua...

Working with Field Sets

Image
A field set is a grouping of fields. For example, you could have a field set that contains fields describing a user's first name, middle name, last name, and business title. Field sets are available for Visualforce pages on API version 21.0 or above. You can have up to 50 field sets referenced on a single page. An sObject can have up to 2,000 field sets. Each field set can have up to 25 fields through lookup relationships. Fields can only span one level away from the entity. Setup Instructions Select the Account object. In the Account object detail page, go to Fields & Relationships. Click "Field Sets" and then "New". Name your field set (e.g., "Account_Details") and add the fields you want to include in the field set. Save the field set. Visualfore Page Example <apex:page standardController="Account">     <apex:form>         <apex:pageBlock title="Account Information">             <apex:pageBlockSecti...

Person Accounts in Salesforce

Image
Person Accounts in Salesforce are a special type of account designed to represent individual consumers rather than businesses or organizations. Enable Person Accounts In Salesforce, Person Accounts are represented by records with the " __pc " suffix appended to their API names. This suffix stands for "Person Account." When Person Accounts are enabled in Salesforce, they create a hybrid record type that combines elements of both the Account and Contact objects into a single record. All standard and custom fields associated with Person Accounts will have the " __pc " suffix appended to their API names. For example, if you have a custom field named " PreferredLanguage__c ," it will appear as " PreferredLanguage__pc " for Person Accounts. Siginificance of a Person Accounts in Salesforce Definition : A Person Account in Salesforce is essentially a hybrid record type that combines elements of both the Account and Contact objects. It represen...

Implement deletion of checked values in a Visualforce page

Here's a simplified example to illustrate the approach: Visualforce Page <apex:page controller="MyController">     <script>         function deleteSelectedRecords() {             var selectedIds = [];             // Loop through checkboxes and collect IDs of checked records             document.querySelectorAll('input[type="checkbox"]:checked').forEach(function(checkbox) {                 selectedIds.push(checkbox.value);             });             // Call server-side method to delete selected records             MyController.deleteRecords(selectedIds, function(result, event) {                 // Handle response from server                 if (event....

Not able to create Trigger on Attachment from Salesforce UI

Image
Salesforce doesn't have the option to allow developers to create triggers directly on standard objects like Attachment using the Salesforce UI.  Instead, we've used tools  Force.com IDE in Eclipse to write and deploy triggers on Attachment. For the Attachment, ContentDocument, and Note standard objects, you can’t create a trigger in the Salesforce user interface. For these objects, create a trigger using development tools, such as the Developer Console or the Salesforce extensions for Visual Studio Code. Alternatively, you can also use the Metadata API. Here's an example

Salesforce Approval Process

Approval Process An approval process automates how records are approved in Salesforce. An approval process specifies each step of approval, including from whom to request approval and what to do at each point of the process. Salesforce Approval Processes allow organizations to automate their approval processes for records, such as leads, opportunities, and custom objects. Here's an example of how you can create an Approval Process for Opportunity records and programmatically submit them for approval using Apex: Define Approval Process in Salesforce Setup: Navigate to Setup > Create > Workflow & Approvals > Approval Processes. Create a new Approval Process for the Opportunity object. Define entry criteria, approval steps, approval actions, and any additional criteria or actions as needed. Activate the Approval Process. Submit Opportunity for Approval using Apex: public with sharing class OpportunityApprovalService {          // Method to submit an O...

Anonymous blocks in the Salesforce Developer Console

Image
Anonymous blocks in the Salesforce Developer Console enable you to run Apex code snippets without defining a separate class or method. This feature is helpful for quickly testing small pieces of Apex code or performing ad-hoc operations in the Salesforce environment.  Log into your org. Click on your name and choose the Developer Console. Here's an example of an anonymous Apex code block that queries the Account object and prints the names of the first 5 accounts: Here are some of the key advantages: Quick Testing: You can quickly test small snippets of Apex code without creating a separate class or method. This makes it easy to experiment with different code constructs, queries, or operations before incorporating them into your larger projects. Ad-hoc Operations: Anonymous blocks allow you to perform ad-hoc operations in the Salesforce environment without writing formal code. For example, you can execute data manipulation operations, perform calculations, or query records direct...