<?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>Stage | Taha Syed | Salesforce</title>
<atom:link href="https://www.syedtaha.com/tag/stage/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>
</channel>
</rss>