How to add users to Public Group using Apex in Salesforce?
To add users to Public Group using Apex, we have to insert the entries in GroupMember entity. As per the following trigger, when a user record is created, the created ....
To add users to Public Group using Apex, we have to insert the entries in GroupMember entity. As per the following trigger, when a user record is created, the created ....
Sample Code: Trigger:trigger Sample on Opportunity (before update, before insert) { if (Trigger.isInsert) { SampleApexClass.SampleMethod(Trigger.new); } else if (Trigger.isUpdate) { SampleApexClass.SampleMethod1(Trigger.new, Trigger.old); }} Apex Class:global class SampleApexClass () { global ....
Sample Code: Trigger:trigger Sample on Opportunity (before update, before insert) { if (Trigger.isInsert) { SampleApexClass.SampleMethod(Trigger.new); } else if (Trigger.isUpdate) { SampleApexClass.SampleMethod1(Trigger.new, Trigger.old); }}Apex Class:global class SampleApexClass () { ....
To update a field in Master record when child record is updated, we have to use Trigger. Sample Trigger: In the below trigger, if a Contact is created or updated, ....
Sample Code: //Adding a Text postFeedItem post = new FeedItem();post.ParentId = oId; //eg. Opportunity id, custom object id..post.Body = 'Enter post text here';insert post;//Adding a Link postFeedItem post = new ....
Messaging.EmailFileAttachment can be used to trigger to send a pdf along with email in Salesforce. Sample Trigger: trigger sendEmail on Employee__c (after insert, after update) { List<Messaging.SingleEmailMessage> mails = new ....
Context Variables in triggers are isExecuting, isInsert, isUpdate, isDelete, isBefore, isAfter, isUndelete, new, newMap, old, oldMap, size. isExecuting Returns true if the current context for the Apex code is a trigger, not ....
Triggers 1. Triggers can work across objects. 2. Coding is required. 3. Trigger works before and after some actions. Workflow rules 1. Workflow Rules will be helpful to update the same object or master ....
Sample Trigger: trigger sample on Account (before insert) { for(Account a : trigger.New) { sampleRest s = new sampleRest(); }} Sample Apex Class: public class sampleRest { ...................... ....
Before Trigger: In case of validation check in the same object. Update the same object. After Trigger: Insert/Update related object, not the same object. Notification email. If we want to ....