Learn Salesforce Apex Triggers with Examples and scenarios

Learn Salesforce Triggers with Examples and Scenarios

Learn Salesforce Triggers with Examples and Scenarios.

 

This post is dedicated to learning Salesforce triggers with examples and scenarios by dissecting them line by line. All triggers will be written with plenty of comments and explanations so that its easier for us to understand and implement.

 

The “Hello World” program is the simplest program used to illustrate the basic syntax of a programming language. The program outputs “Hello World” and is traditionally the first program written by all beginner developers. Our Hello World trigger’s requirement is: When a Lead is updated, update the lead’s first name to ‘Hello’ and the last name to ‘World’

 

Every time an Opportunity is created (and the user selects any Stage), the Opportunity Stage should change and default to Prospecting.

 

When an Opportunity is updated, a new Task should be created and assigned to the Opportunity Owner. The status of the task should be “In Progress”

 

On each Account, the Total Salary custom field should hold the sum of Salaries from its associated Contacts. The trigger should work whenever a Contact’s Salary is updated, New Contact is Created or when an existing Contact is deleted.

 

When a Contact is being created and if a record with the same Email Id or Phone number exists, the trigger should throw an error and the User should not be allowed to create the Duplicate Contact

 

When a user posts to chatter and if the user’s post contains the term “Success”, an automated comment should be posted. This comment should be randomly selected from a list of comments; And should be posted as a specific user.

 

 

Please support this post by linking it from your website/blog
http://www.syedtaha.com/salesforce-apex-triggers/learn-salesforce-triggers-with-examples-and-scenarios/1072/

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.