<?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>lead | Taha Syed | Salesforce</title>
<atom:link href="https://www.syedtaha.com/tag/lead/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>Sat, 07 Jul 2018 16:10:40 +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>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
fetchpriority="high" 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
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="(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>