<?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>Ajax Toolkit &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/ajax-toolkit/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Tue, 03 Nov 2015 21:54:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Create and update records using Javascript button in Salesforce- Ajax Toolkit</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Tue, 21 Apr 2015 18:39:01 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Ajax Toolkit]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Salesforce Ajax Toolkit]]></category>
		<guid isPermaLink="false">http://www.jitendrazaa.com/blog/?p=4394</guid>

					<description><![CDATA[On this blog we have already seen &#8220;how to use Ajax Toolkit to mass update records&#8221; without writing any Apex code. In this article as well, we will use Ajax Toolkit to add custom button in Account page layout and update record. There are endless possibilities and use-cases where this approach can be very useful [&#8230;]]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">On this blog we have already seen &#8220;<a title="Create Simple Mass Delete Button for ListView using Salesforce Ajax Toolkit" href="https://www.jitendrazaa.com/blog/salesforce/create-simple-mass-delete-button-for-listview-using-javascript/">how to use Ajax Toolkit to mass update records</a>&#8221; without writing any Apex code. In this article as well, we will use <a title="Salesforce - The AJAX Toolkit" href="http://www.salesforce.com/us/developer/docs/ajax/">Ajax Toolkit</a> to add custom button in Account page layout and update record.</p>
<p style="text-align: justify;">There are endless possibilities and use-cases where this approach can be very useful in Salesforce projects and can be accomplished by Salesforce admins. Lets say we want to create child record on click of button, Update current record on basis of some logic, Update hidden fields, execute existing Apex code using Javascript and so on. All of these can be implemented wthout writing single line of Apex code, Trigger or Visualforce pages.</p>
<p style="text-align: justify;">In this post, we will add custom button on Account detail page and execute Javascript to update Account name using Ajax toolkit. This is just proof of concept and any other field can be updated.</p>
<p><strong>Creating Custom button :</strong></p>
<p>Navigate to &#8220;Customize | Accounts | Button, Links and Actions&#8221;.</p>
<p style="text-align: justify;">Create new button of type &#8220;Detail Page Button&#8221; , behavior &#8220;Execute Javascript&#8221; and content source &#8220;Onclick JavaScript&#8221;.</p>
<p><a href="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Javascript.png?ssl=1"><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="wp-image-4395" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Javascript.png?resize=550%2C424&#038;ssl=1" alt="Update Record using Javascript" width="550" height="424" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Javascript.png?w=941&amp;ssl=1 941w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Javascript.png?resize=300%2C231&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Javascript.png?resize=624%2C481&amp;ssl=1 624w" sizes="(max-width: 550px) 100vw, 550px" /></a></p>
<p>Update Record using Javascript</p>
<p><span id="more-4394"></span></p>
<p><strong>Javascript code :</strong></p>
<pre class="brush: jscript; title: ; notranslate">
{!REQUIRESCRIPT(&quot;/soap/ajax/33.0/connection.js&quot;)}
{!REQUIRESCRIPT(&quot;/soap/ajax/33.0/apex.js&quot;)} 

var accnt = new sforce.SObject(&quot;Account&quot;);
accnt.Id = '{!Account.Id}';
accnt.Name = prompt('Enter new Account Name','{!Account.Name}');

var result = sforce.connection.update(&#x5B;accnt]);
if(result&#x5B;0].getBoolean(&quot;success&quot;))
{
   alert('Account updated successfully');
   window.location.reload();
}
else{
  alert('Error : '+result);
}
</pre>
<p style="text-align: justify;">Add this newly created button on Account page layout and click on it. It would prompt for new name and will update current record.</p>
<figure id="attachment_4396" aria-describedby="caption-attachment-4396" style="width: 625px" class="wp-caption alignleft"><a href="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Salesforce-AJAX-Toolkit.png?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-large wp-image-4396" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Salesforce-AJAX-Toolkit.png?resize=625%2C197&#038;ssl=1" alt="Update Record using Salesforce AJAX Toolkit" width="625" height="197" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Salesforce-AJAX-Toolkit.png?resize=1024%2C322&amp;ssl=1 1024w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Salesforce-AJAX-Toolkit.png?resize=300%2C94&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Salesforce-AJAX-Toolkit.png?resize=624%2C196&amp;ssl=1 624w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/04/Update-Record-using-Salesforce-AJAX-Toolkit.png?w=1116&amp;ssl=1 1116w" sizes="(max-width: 625px) 100vw, 625px" /></a><figcaption id="caption-attachment-4396" class="wp-caption-text">Update Record using Salesforce AJAX Toolkit</figcaption></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4394</post-id>	</item>
		<item>
		<title>Apex Interview Question – Salesforce &#8211; Part 16</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/apex-interview-question-salesforce-part-16/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/apex-interview-question-salesforce-part-16/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Sun, 28 Jul 2013 07:57:42 +0000</pubDate>
				<category><![CDATA[Apex]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Ajax Toolkit]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[SOQL]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=3411</guid>

					<description><![CDATA[151. Give Sample Code Snippet of Apex that that will show that how Parent and Child record can be inserted in Single Statement ? Ans : It can be done with help of External Id. Date dt = Date.today().addDays(7); Opportunity newOpportunity = new Opportunity(Name = 'shivasoft', StageName = 'Prospecting', CloseDate = dt); /* Create the [&#8230;]]]></description>
										<content:encoded><![CDATA[<div class="intrinsic-container"><iframe src="https://jitendrazaa.com/blog/SFDCInterviewList.php?num=16" width="300" height="150" allowfullscreen="allowfullscreen"> </iframe></div>
<p><strong>151. Give Sample Code Snippet of Apex that that will show that how Parent and Child record can be inserted in Single Statement ?</strong><br />
<strong> Ans :</strong> It can be done with help of External Id.</p>
<pre class="brush: java; title: ; notranslate">
Date dt = Date.today().addDays(7);
Opportunity newOpportunity = new Opportunity(Name = 'shivasoft', StageName = 'Prospecting', CloseDate = dt);

/*
Create the parent reference. Used only for foreign key reference  and doesn't contain any other fields. If we provide any other value it will give following error

System.DmlException: Insert failed. First exception on row 1; first error: INVALID_FIELD, More than 1 field provided in an external foreign key reference in entity: Account: &#x5B;]
*/

Account accountReference = new Account(MyExtID__c = 'SHIVA1234567');
newOpportunity.Account = accountReference;

//  Create the Account object to insert.  Same as above but has Name field.  Used for the insert.
Account parentAccount = new Account(Name = 'Shiva', MyExtID__c = 'SHIVA1234567');

Database.SaveResult&#x5B;]
    results = Database.insert(new SObject&#x5B;] {  parentAccount, newOpportunity });

</pre>
<hr />
<p><strong>152 . Which SOQL statement can be used to get all records even from recycle bin or Achieved Activities?</strong><br />
<strong> Ans :</strong> We will need &#8220;ALL Rows&#8221; clause of SOQL.<br />
Sample :</p>
<pre class="brush: sql; title: ; notranslate">
SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS
</pre>
<hr />
<p><strong>153. How can you lock record using SOQL so that it cannot be modified by other user.</strong><br />
<strong> Ans :</strong> we will need &#8220;FOR UPDATE&#8221; clause of SOQL.<br />
Sample :</p>
<pre class="brush: sql; title: ; notranslate">
 Account &#x5B;] accts = &#x5B;SELECT Id FROM Account LIMIT 2 FOR UPDATE];
</pre>
<hr />
<p><strong><span id="more-3411"></span>154. If you set more than one savepoint, then roll back to a savepoint that is not the last savepoint you generated, What will happen to later savepoint variables ?</strong><br />
<strong> Ans :</strong> if you generated savepoint SP1 first, savepoint SP2 after that, and then you rolled back to SP1, the variable SP2 would no longer be valid. You will receive a runtime error if you try to use it.</p>
<hr />
<p><strong>155. What are few limitations (points to remember) of Savepoint or Transaction Control in Apex ?</strong><br />
<strong> Ans :</strong></p>
<ul>
<li>Each savepoint you set counts against the governor limit for DML statements.</li>
<li>Static variables are not reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.</li>
<li>Each rollback counts against the governor limit for DML statements. You will receive a Runtime error if you try to rollback the database additional times.</li>
<li>The ID on an sObject inserted after setting a savepoint is not cleared after a rollback.</li>
</ul>
<hr />
<p><strong>156. What are few Considerations about Trigger ?</strong><br />
<strong> Ans :</strong></p>
<ul>
<li><strong>upsert</strong> triggers fire both before and after insert or before and after update triggers as appropriate.</li>
<li><strong>merge</strong> triggers fire both before and after delete triggers for the losing records and before update triggers for the winning record only.</li>
<li>Triggers that execute after a record has been <strong>undeleted</strong> only work with specific objects.</li>
<li>Field history is not recorded until the end of a trigger. If you query field history in a trigger, you will not see any history for the current transaction.</li>
<li>You can only use the <strong>webService</strong> keyword in a trigger when it is in a method defined as asynchronous; that is, when the method is defined with the <strong>@future</strong> keyword.</li>
<li>A trigger invoked by an insert, delete, or update of a <strong>recurring event</strong> or <strong>recurring task</strong> results in a runtime error when the trigger is called in bulk from the Force.com API.</li>
<li><strong>Merge</strong> trigger doesn&#8217;t fire there own trigger instead they fire delete and update of loosing and winning records respectively.</li>
</ul>
<hr />
<p><strong>157. How to execute Apex from Custom button or Javascript ? Give Example.</strong><br />
<strong> Ans :</strong></p>
<p>It is possible using <a href="https://www.jitendrazaa.com/blog/tag/ajax-toolkit/">Ajax toolkiit</a>.</p>
<pre class="brush: java; title: ; notranslate">
global class myClass {
	webService static Id makeContact (String lastName, Account a) {
		Contact c = new Contact(LastName = lastName, AccountId = a.Id);
		return c.id;
	}
}
</pre>
<p>we can execute above method from javascript like :</p>
<pre class="brush: java; title: ; notranslate">
{!REQUIRESCRIPT(&quot;/soap/ajax/33.0/connection.js&quot;)} 
{!REQUIRESCRIPT(&quot;/soap/ajax/33.0/apex.js&quot;)} 
var account = sforce.sObject(&quot;Account&quot;);
var id = sforce.apex.execute(&quot;myClass&quot; , &quot;makeContact&quot;,
{lastName:&quot;Smith&quot;, a:account});
</pre>
<p>To call a webService method with no parameters, use {} as the third parameter for <strong> sforce.apex.execute </strong>.</p>
<p>Also, you can use the following line to display a popup window with debugging information:<br />
<strong> sforce.debug.trace=true; </strong></p>
<hr />
<p><strong>158.  What is difference between public and global class in Apex ?</strong><br />
<strong> Ans :</strong></p>
<ul>
<li>Public class can be accessed within application or namespace. This is not exactly like public modifier in Java.</li>
<li>Global class visible everywhere , any application or namespace. WebService must be declared as Global and which can be accessed inside Javascript also. It is like public modifier in Java.</li>
</ul>
<hr />
<p><strong>159. Explain Considerations for Static keyword in Apex.</strong></p>
<p><strong>Ans :</strong></p>
<ul>
<li>Apex classes cannot be static.</li>
<li>Static allowed only in outer class.</li>
<li>Static variables not transferred as a part of View State.</li>
<li>Static variables and static block runs in order in which they are written in class.</li>
<li>Static variables are static only in scope of request.</li>
</ul>
<hr />
<p><strong>160. Explain few considerations for @Future annotation in Apex.</strong></p>
<p><strong>Ans :</strong></p>
<ul>
<li>Method must be static</li>
<li>Cannot return anything ( Only Void )</li>
<li>To test @future methods, you should use startTest and stopTest to make it synchromouse inside Test class.</li>
<li>Parameter to @future method can only be primitive or collection of primitive data type.</li>
<li>Cannot be used inside VF in Constructor, Set or Get methods.</li>
<li>@future method cannot call other @future method.</li>
</ul>
<div class="intrinsic-container"><iframe src="https://jitendrazaa.com/blog/SFDCInterviewList.php?num=16" width="300" height="150" allowfullscreen="allowfullscreen"> </iframe></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/apex-interview-question-salesforce-part-16/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3411</post-id>	</item>
		<item>
		<title>Create Simple Mass Delete Button for ListView using Salesforce Ajax Toolkit</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/create-simple-mass-delete-button-for-listview-using-javascript/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/create-simple-mass-delete-button-for-listview-using-javascript/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Mon, 06 May 2013 15:31:05 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Ajax Toolkit]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[Salesforce Ajax Toolkit]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=3299</guid>

					<description><![CDATA[In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click &#8220;Delete&#8221; button. In this example, we will create a simple List View button and add on &#8220;Search Layout&#8221; of that object. So, create a new Custom Button with following property: Display Type :  List Button [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click &#8220;Delete&#8221; button.</p>
<p>In this example, we will create a simple List View button and add on &#8220;Search Layout&#8221; of that object.</p>
<figure id="attachment_3301" aria-describedby="caption-attachment-3301" style="width: 594px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2013/05/Salesforce-Mass-Delete-Button-List-View.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-3301" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2013/05/Salesforce-Mass-Delete-Button-List-View.png?resize=594%2C211&#038;ssl=1" alt="Salesforce Mass Delete Button - List View" width="594" height="211" /></a><figcaption id="caption-attachment-3301" class="wp-caption-text">Salesforce Mass Delete Button &#8211; List View</figcaption></figure>
<p>So, create a new Custom Button with following property:</p>
<ol>
<li><strong>Display Type</strong> :  List Button</li>
<li><strong>Behavior</strong> : Execute JavaScript</li>
<li><strong>Content Source</strong> :  OnClick JavaScript</li>
</ol>
<p>and use below Source code:<span id="more-3299"></span></p>
<pre class="brush: java; highlight: [4]; title: ; notranslate">
{!REQUIRESCRIPT(&quot;/soap/ajax/21.0/connection.js&quot;)}

//Below ObjectType can be replaced by anyObject. I have used &quot;Test Name&quot;
var records = {!GETRECORDIDS($ObjectType.Test_Name__c)};

if (records&#x5B;0] == null) {
    alert(&quot;Please select at least one record.&quot;)
} else {

    var opt = confirm(&quot;Are you sure you want to delete selected records ?&quot;);
    if (opt == true) {
        var errors = &#x5B;];
        var result = sforce.connection.deleteIds(records);
        if (result &amp;&amp; result.length) {
            var numFailed = 0;
            var numSucceeded = 0;
            for (var i = 0; i &lt; result.length; i++) {                 var res = result&#x5B;i];                 if (res &amp;&amp; res.success == 'true') {                     numSucceeded++;                 } else {                     var es = res.getArray(&quot;errors&quot;);                     if (es.length &gt; 0) {
                        errors.push(es&#x5B;0].message);
                    }
                    numFailed++;
                }
            }
            if (numFailed &gt; 0) {
                alert(&quot;Failed: &quot; + numFailed + &quot;nSucceeded: &quot; + numSucceeded + &quot; n Due to: &quot; + errors.join(&quot;n&quot;));
            } else {
                alert(&quot;Number of records deleted: &quot; + numSucceeded);
            }
        }
        window.location.reload();
    }
}
</pre>
<p>In above code, we only need to change line number 4 for Object Type.<br />
Once you are done with above button, add button in Search Layout&#8217;s List View as shown in below Image.</p>
<figure id="attachment_3300" aria-describedby="caption-attachment-3300" style="width: 529px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2013/05/Salesforce-Search-Layout.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class=" wp-image-3300 " src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2013/05/Salesforce-Search-Layout.png?resize=529%2C193&#038;ssl=1" alt="Salesforce Search Layout" width="529" height="193" /></a><figcaption id="caption-attachment-3300" class="wp-caption-text">Salesforce Search Layout</figcaption></figure>
<p><a title="Salesforce Cookbook" href="https://ap1.salesforce.com/help/doc/en/links_useful_custom_buttons_mass_delete.htm" rel="nofollow">Code taken from Salesforce Cookbook</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/create-simple-mass-delete-button-for-listview-using-javascript/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3299</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-07-26 04:40:46 by W3 Total Cache
-->