<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>beginners triggers | Taha Syed | Salesforce</title>
<atom:link href="https://www.syedtaha.com/tag/beginners-triggers/feed/" rel="self" type="application/rss+xml" /><link>https://www.syedtaha.com</link>
<description>Taha Syed &#124; Sales to Salesforce &#124; Dissecting and Defining the Rationale..</description>
<lastBuildDate>Wed, 25 Jul 2018 22:02:46 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>
hourly	</sy:updatePeriod>
<sy:updateFrequency>
1	</sy:updateFrequency>
<generator>https://wordpress.org/?v=6.9.4</generator>
<item><title>Trigger to change the Stage when Opportunity is Created &#8211; Triggers for Beginners</title><link>https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-change-the-stage-when-opportunity-is-created-triggers-for-beginners/979/</link>
<comments>https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-change-the-stage-when-opportunity-is-created-triggers-for-beginners/979/#respond</comments>
<dc:creator><![CDATA[Taha Syed]]></dc:creator>
<pubDate>Wed, 25 Jul 2018 22:02:46 +0000</pubDate>
<category><![CDATA[Apex Triggers]]></category>
<category><![CDATA[apex trigger]]></category>
<category><![CDATA[beginners triggers]]></category>
<category><![CDATA[Opportunity Trigger]]></category>
<category><![CDATA[salesforce trigger]]></category>
<category><![CDATA[Stage]]></category>
<guid
isPermaLink="false">http://www.syedtaha.com/?p=979</guid><description><![CDATA[<p>Salesforce Apex Trigger to change the Stage/default the stage to 'Prospecting' when an Opportunity is created. In other words, when an Opportunity is created by selecting any Stage, the Stage should default back to Prospecting.</p>
The post <a
href="https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-change-the-stage-when-opportunity-is-created-triggers-for-beginners/979/">Trigger to change the Stage when Opportunity is Created – Triggers for Beginners</a> first appeared on <a
href="https://www.syedtaha.com">Taha Syed | Salesforce</a>.]]></description>
<content:encoded><![CDATA[<h1>Salesforce Apex Triggers for Beginners: Change the Stage when an Opportunity is created.</h1><p><strong>Requirement:</strong> Write a Salesforce Apex Trigger to change the Stage/default the stage to &#8216;Prospecting&#8217; when an Opportunity is created. In other words, when an Opportunity is created by selecting any Stage, the Stage should default back to Prospecting.</p><p>Lets start by revisiting the Salesforce Apex Trigger Syntax:</p><pre class="lang:default decode:true " title="Salesforce Apex Trigger Syntax">trigger *triggerName* on *Object* (*before/after event*) {
    for (*Object* *Variable* : Trigger.New)      
        **Trigger Actions &amp; Code Block**
}</pre><p>We will write the trigger in the following three Steps:</p><ol><li>Define the trigger</li><li>Build a &#8216;For Each&#8217; loop to iterate through each record</li><li>Update the Stage</li></ol><p>Now lets write each Step for this trigger.</p><div
class="tab_widget wp_shortcodes_tabs"><ul
class="wps_tabs"><li><a
href="#" data-tab="tab-0-step-1">Step 1</a></li><li><a
href="#" data-tab="tab-1-step-2">Step 2</a></li><li><a
href="#" data-tab="tab-2-step-3">Step 3</a></li></ul><div
class="tab_container"><div
id="tab-0-step-1" class="tab_content clearfix"></p><pre class="lang:default decode:true ">//Defining the Trigger - Trigger Name, Object and Events.
trigger DefaultStageProspecting on Opportunity (before insert) {</pre><p>&nbsp;</p><p></div><div
id="tab-1-step-2" class="tab_content clearfix"></p><pre class="lang:default decode:true ">    //For each Opportunity record being updated, assign the variable 'Opp' to it.
    for ( Opportunity Opp :Trigger.New) {</pre><p>&nbsp;</p><p></div><div
id="tab-2-step-3" class="tab_content clearfix"></p><pre class="lang:default decode:true ">// Update the Stage to 'Prospecting'    
    Opp.StageName = 'Prospecting';

    }
}</pre><p>&nbsp;</p><p></div></div></div><div
class="clear"></div><p>The complete Trigger to change the Stage when Opportunity is Created would be:</p><pre class="lang:default decode:true ">//Defining the Trigger - Trigger Name, Object and Events.
trigger DefaultStageProspecting on Opportunity (before insert) {

    //For each Opportunity record being updated, assign the variable 'Opp' to it.
    for ( Opportunity Opp :Trigger.New) {
    
	// Update the Stage to 'Prospecting'    
    Opp.StageName = 'Prospecting';

    }
}</pre><p>This is how the Trigger looks in the Developer Console (Image)</p><figure
id="attachment_980" aria-describedby="caption-attachment-980" style="width: 924px" class="wp-caption alignleft"><img
fetchpriority="high" decoding="async" class="wp-image-980 size-full" title="Trigger to Update StageName" src="http://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-Update-StageName.png" alt="Trigger to Update StageName" width="924" height="509" srcset="https://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-Update-StageName.png 924w, https://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-Update-StageName-300x165.png 300w, https://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-Update-StageName-768x423.png 768w" sizes="(max-width: 924px) 100vw, 924px" /><figcaption
id="caption-attachment-980" class="wp-caption-text">Trigger to Update StageName</figcaption></figure><p>&nbsp;</p>The post <a
href="https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-change-the-stage-when-opportunity-is-created-triggers-for-beginners/979/">Trigger to change the Stage when Opportunity is Created – Triggers for Beginners</a> first appeared on <a
href="https://www.syedtaha.com">Taha Syed | Salesforce</a>.]]></content:encoded>
<wfw:commentRss>https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-change-the-stage-when-opportunity-is-created-triggers-for-beginners/979/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
<item><title>Write Your First Hello World Salesforce Apex Trigger &#8211; Triggers for Beginners</title><link>https://www.syedtaha.com/salesforce-apex-triggers/write-your-first-hello-world-salesforce-apex-trigger-triggers-for-beginners/946/</link>
<comments>https://www.syedtaha.com/salesforce-apex-triggers/write-your-first-hello-world-salesforce-apex-trigger-triggers-for-beginners/946/#respond</comments>
<dc:creator><![CDATA[Taha Syed]]></dc:creator>
<pubDate>Tue, 03 Jul 2018 20:57:23 +0000</pubDate>
<category><![CDATA[Apex Triggers]]></category>
<category><![CDATA[apex]]></category>
<category><![CDATA[apex trigger]]></category>
<category><![CDATA[beginners triggers]]></category>
<category><![CDATA[lead]]></category>
<category><![CDATA[salesforce trigger]]></category>
<category><![CDATA[triggers]]></category>
<guid
isPermaLink="false">http://www.syedtaha.com/?p=946</guid><description><![CDATA[<p>Let's write our first "Hello World" Salesforce Apex trigger which will update a Lead with "Hello" as the first name and World" as the last name.<br
/>
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.</p>
The post <a
href="https://www.syedtaha.com/salesforce-apex-triggers/write-your-first-hello-world-salesforce-apex-trigger-triggers-for-beginners/946/">Write Your First Hello World Salesforce Apex Trigger – Triggers for Beginners</a> first appeared on <a
href="https://www.syedtaha.com">Taha Syed | Salesforce</a>.]]></description>
<content:encoded><![CDATA[<h1>Apex Triggers for Beginners</h1><p>The &#8220;Hello World&#8221; program is the simplest program used to illustrate the basic syntax of a programming language. The program outputs &#8220;Hello World&#8221; and is traditionally the first program written by all beginner developers.</p><p>Let&#8217;s write our first &#8220;Hello World&#8221; Salesforce Apex trigger which will update a Lead with &#8220;Hello&#8221; as the first name and &#8220;World&#8221; as the last name.</p><p><strong>Requirement:</strong><br
/>
When a Lead is updated, update the lead&#8217;s first name to &#8216;Hello&#8217; and last name to &#8216;World&#8217;</p><p>Lets write the trigger in the &#8220;Developer Console&#8221;. To access the developer console, click the drop down on your <strong>Name</strong> (on the top right), and then click on <strong>Developer Console.</strong></p><figure
id="attachment_950" aria-describedby="caption-attachment-950" style="width: 1024px" class="wp-caption alignnone"><img
decoding="async" class="wp-image-950 size-large" src="http://www.syedtaha.com/wp-content/uploads/2018/07/Salesforce-Developer-Console-1024x185.png" alt="Salesforce Developer Console" width="1024" height="185" srcset="https://www.syedtaha.com/wp-content/uploads/2018/07/Salesforce-Developer-Console-1024x185.png 1024w, https://www.syedtaha.com/wp-content/uploads/2018/07/Salesforce-Developer-Console-300x54.png 300w, https://www.syedtaha.com/wp-content/uploads/2018/07/Salesforce-Developer-Console-768x139.png 768w, https://www.syedtaha.com/wp-content/uploads/2018/07/Salesforce-Developer-Console.png 1551w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption
id="caption-attachment-950" class="wp-caption-text">Salesforce Developer Console</figcaption></figure><p>&nbsp;</p><p>Once the developer console is open, click on <strong>File &gt;&gt; Open &gt;&gt; Apex Trigger. </strong>Now we are ready to write our first trigger.</p><figure
id="attachment_951" aria-describedby="caption-attachment-951" style="width: 560px" class="wp-caption aligncenter"><img
decoding="async" class="wp-image-951 size-full" src="http://www.syedtaha.com/wp-content/uploads/2018/07/Open-Apex-Trigger-in-Developer-Console.png" alt="Open Apex Trigger in Developer Console" width="560" height="421" srcset="https://www.syedtaha.com/wp-content/uploads/2018/07/Open-Apex-Trigger-in-Developer-Console.png 560w, https://www.syedtaha.com/wp-content/uploads/2018/07/Open-Apex-Trigger-in-Developer-Console-300x226.png 300w, https://www.syedtaha.com/wp-content/uploads/2018/07/Open-Apex-Trigger-in-Developer-Console-320x240.png 320w" sizes="(max-width: 560px) 100vw, 560px" /><figcaption
id="caption-attachment-951" class="wp-caption-text">Open Apex Trigger in Developer Console</figcaption></figure><p>&nbsp;</p><p><strong>The Trigger Syntax:</strong><br
/>
Every trigger is defined by using the following syntax:</p><pre class="top-margin:20 bottom-margin:20 left-margin:20 right-margin:20 lang:go range:1-10 decode:true">  trigger *triggerName* on *Object* (*before/after event*) {
       for (*Object* *Variable* : Trigger.New)
       **Trigger Actions &amp; Code Block**
  }</pre><p>&nbsp;</p><p>Here is what the terms in the syntax mean:</p><ul><li>&#8216;triggerName&#8217; is the name of the trigger which describes it.</li><li>&#8216;Object&#8217; is the name of the Object on which the trigger is created</li><li>&#8216;before/after event&#8217; are a comma separated list of events like insert, update, delete</li><li>&#8216;Trigger.New&#8217; is a list of sObject records</li><li>&#8216;Variable&#8217; denote a piece of memory that can contain a data value. Descriptive text is used as variables.</li></ul><p>Lets get back to our requirement and based on the above syntax, write our <strong>&#8216;Hello World&#8217; Salesforce Apex trigger</strong>.<br
/>
Remember, when a <strong>Lead</strong> is <strong>updated</strong>, the <strong>first nam</strong>e should be updated to &#8220;<strong>Hello</strong>&#8221; and the <strong>Last Name</strong> to &#8220;<strong>World</strong>&#8220;.</p><p>We will be using <strong>comments</strong> to <strong>describe the lines of code</strong> in our <strong>trigger</strong>. But what are comments? <strong>Comments are used to describe code</strong> and are ignored by the parser &#8211; meaning the comments are NOT treated as code and will not run.<br
/>
Single line comments are preceded by // and multi line comments are wrapped in /* and */</p><p>Now here comes the trigger:</p><pre class="lang:default decode:true">// Name of the trigger is HelloWorld, It is on the Lead Object and It will run before the lead is updated (event).
trigger HelloWorld on Lead (before update) {
        //for every lead record, denoted by variable ld,in the list that is being updated
        for (lead ld : Trigger.new) {
             // add the first name as 'Hello'
             ld.FirstName = 'Hello';
             // add the last name as 'World'
             ld.LastName = 'World';
         }
}</pre><p>&nbsp;</p><p>This is how it looks in the developer console.</p><figure
id="attachment_955" aria-describedby="caption-attachment-955" style="width: 726px" class="wp-caption alignnone"><img
loading="lazy" decoding="async" class="wp-image-955 size-full" src="http://www.syedtaha.com/wp-content/uploads/2018/07/Hello-World-Salesforce-Apex-Trigger-1.png" alt="Hello World Salesforce Apex Trigger" width="726" height="354" srcset="https://www.syedtaha.com/wp-content/uploads/2018/07/Hello-World-Salesforce-Apex-Trigger-1.png 726w, https://www.syedtaha.com/wp-content/uploads/2018/07/Hello-World-Salesforce-Apex-Trigger-1-300x146.png 300w" sizes="auto, (max-width: 726px) 100vw, 726px" /><figcaption
id="caption-attachment-955" class="wp-caption-text">Hello World Salesforce Apex Trigger</figcaption></figure><p>&nbsp;</p><p><strong>Exercise to get used to the syntax and the basic trigger for beginners:</strong></p><p>Write a trigger to update the first name of the contact as Taha and the last name as Syed and the Phone number as 000-111-9999</p>The post <a
href="https://www.syedtaha.com/salesforce-apex-triggers/write-your-first-hello-world-salesforce-apex-trigger-triggers-for-beginners/946/">Write Your First Hello World Salesforce Apex Trigger – Triggers for Beginners</a> first appeared on <a
href="https://www.syedtaha.com">Taha Syed | Salesforce</a>.]]></content:encoded>
<wfw:commentRss>https://www.syedtaha.com/salesforce-apex-triggers/write-your-first-hello-world-salesforce-apex-trigger-triggers-for-beginners/946/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
</channel>
</rss>