<?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>create task | Taha Syed | Salesforce</title>
<atom:link href="https://www.syedtaha.com/tag/create-task/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 19:59:31 +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 create task when Opportunity is updated &#8211; Salesforce Apex Triggers</title><link>https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-create-task-when-opportunity-is-updated-salesforce-apex-triggers/958/</link>
<comments>https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-create-task-when-opportunity-is-updated-salesforce-apex-triggers/958/#respond</comments>
<dc:creator><![CDATA[Taha Syed]]></dc:creator>
<pubDate>Wed, 25 Jul 2018 19:57:06 +0000</pubDate>
<category><![CDATA[Apex Triggers]]></category>
<category><![CDATA[apex]]></category>
<category><![CDATA[create task]]></category>
<category><![CDATA[opportunity]]></category>
<category><![CDATA[salesforce trigger]]></category>
<category><![CDATA[trigger on opportunity]]></category>
<category><![CDATA[triggers]]></category>
<guid
isPermaLink="false">http://www.syedtaha.com/?p=958</guid><description><![CDATA[<p>Salesforce Apex Trigger to create a Task when an Opportunity is updated. The task should be assigned to the Opportunity owner and the status of the task should be "In Progress". - Salesforce Apex Trigger Examples</p>
The post <a
href="https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-create-task-when-opportunity-is-updated-salesforce-apex-triggers/958/">Trigger to create task when Opportunity is updated – Salesforce Apex Triggers</a> first appeared on <a
href="https://www.syedtaha.com">Taha Syed | Salesforce</a>.]]></description>
<content:encoded><![CDATA[<h1>Trigger to create a task when an Opportunity is updated &#8211; Salesforce Apex Triggers for Beginners.</h1><p><strong>Requirement: </strong>Write a Salesforce Apex Trigger to create a Task when an Opportunity is updated. The task should be assigned to the Opportunity owner and the status of the task should be &#8220;In Progress&#8221;.</p><p><strong>The Salesforce Apex Trigger Sytax is as follows:</strong></p><pre class="lang:default decode:true" title="Apex Trigger Syntax">trigger *triggerName* on *Object* (*before/after event*) {
    for (*Object* *Variable* : Trigger.New)      
        **Trigger Actions &amp; Code Block**
}</pre><p>&nbsp;</p><p>Now lets write our trigger with the following steps.</p><ol><li> Define the trigger</li><li> Iterate through each opportunity</li><li> Create a Task</li><li> Assign values to the Task</li></ol><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><li><a
href="#" data-tab="tab-3-step-4">Step 4</a></li></ul><div
class="tab_container"><div
id="tab-0-step-1" class="tab_content clearfix"><br
/>
////define the trigger name, object and events</p><pre class="lang:default decode:true">trigger createTaskOnOpp on Opportunity (before update) {</pre><p></div><div
id="tab-1-step-2" class="tab_content clearfix"><br
/>
//Iterate through each opportunity and assign it the variable Opp</p><pre class="lang:default decode:true ">for (Opportunity Opp :Trigger.New) {</pre><p></div><div
id="tab-2-step-3" class="tab_content clearfix"><br
/>
//Create a new task and assign it the variable <strong>t</strong></p><pre class="lang:default decode:true ">Task t = new Task();</pre><p></div><div
id="tab-3-step-4" class="tab_content clearfix"></p><p>//Assign Values to the task <strong>t</strong></p><pre class="lang:default decode:true">	t.WhatID = Opp.Id;
	t.Ownerid = opp.Ownerid;
	t.subject = 'This is the Subject';
	t.Status = 'In Progress';
	t.Description = 'This is the Description';
	insert t;
	}
}</pre><p></div></div></div><div
class="clear"></div><p>The complete Salesforce Apex Trigger to create a Task when an Opportunity is updated would be:</p><pre class="lang:default decode:true">////define the trigger name, object and events
trigger createTaskOnOpp on Opportunity (before update) {
    //Iterate through each opportunity and assign it the variable Opp
    for (Opportunity Opp :Trigger.New) {
	//Create a new task and assign it the variable t
        Task t = new Task();
        // Assign Values to the task t
        t.WhatID          = Opp.Id;
        t.Ownerid         = opp.Ownerid;
        t.subject 	  = 'This is the Subject';
        t.Status	  = 'In Progress';
        t.Description     = 'This is the Description';
        insert t;
    }
}</pre><p>&nbsp;</p><p>This is how the trigger looks in the developer console (image)</p><figure
id="attachment_976" aria-describedby="caption-attachment-976" style="width: 818px" class="wp-caption alignnone"><img
fetchpriority="high" decoding="async" class="wp-image-976 size-full" src="http://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-create-Task-when-Opportunity-is-updated.png" alt="Trigger to create Task when Opportunity is updated" width="818" height="514" srcset="https://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-create-Task-when-Opportunity-is-updated.png 818w, https://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-create-Task-when-Opportunity-is-updated-300x189.png 300w, https://www.syedtaha.com/wp-content/uploads/2018/07/Trigger-to-create-Task-when-Opportunity-is-updated-768x483.png 768w" sizes="(max-width: 818px) 100vw, 818px" /><figcaption
id="caption-attachment-976" class="wp-caption-text">Trigger to create Task when Opportunity is updated</figcaption></figure><p>&nbsp;</p><p>&nbsp;</p>The post <a
href="https://www.syedtaha.com/salesforce-apex-triggers/trigger-to-create-task-when-opportunity-is-updated-salesforce-apex-triggers/958/">Trigger to create task when Opportunity is updated – Salesforce Apex Triggers</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-create-task-when-opportunity-is-updated-salesforce-apex-triggers/958/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
</channel>
</rss>