function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Thorsten Haude 5Thorsten Haude 5 

Who am I?

Hi,

I'm writing a button on a Case page that
1. gets some values from the local Case:
var name = "{!Case.Subject}";

2. Puts them into an Apex call to create a different object.
3. should write some stuff back into the local case, so
{!Case.Project__c} =  project;

...which does not work.

So what is the way to set the local record's fields in Javascript?

Thanks!

Cheers,
Thorsten

Best Answer chosen by Thorsten Haude 5
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi 

You need to use the AJAX Toolkit. Set the detail button to execute a bit of javascript on click.
 
{!requireScript("/soap/ajax/26.0/connection.js")} var account = new sforce.SObject("Account"); account.id = //set Record Id here, potentially get it from the URL ?id= param account.field__c = value; sforce.connection.update([account]); window.location.reload(); //to reload the window and show the updated values
Reference : http://www.salesforce.com/us/developer/docs/ajax/index.htm

Refer this link (http://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/)
So, in summary its either the AJAX Toolkit or Apex, nothing else is possible.



Hope this helps !!
--
Thanks,
Swayam 

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hi 

You need to use the AJAX Toolkit. Set the detail button to execute a bit of javascript on click.
 
{!requireScript("/soap/ajax/26.0/connection.js")} var account = new sforce.SObject("Account"); account.id = //set Record Id here, potentially get it from the URL ?id= param account.field__c = value; sforce.connection.update([account]); window.location.reload(); //to reload the window and show the updated values
Reference : http://www.salesforce.com/us/developer/docs/ajax/index.htm

Refer this link (http://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/)
So, in summary its either the AJAX Toolkit or Apex, nothing else is possible.



Hope this helps !!
--
Thanks,
Swayam 
This was selected as the best answer
Thorsten Haude 5Thorsten Haude 5
The link to Jitendra's page pushed me on the right path, it works for me now!

Thank you very much!