+ Start a Discussion
Raju Sudheer 3Raju Sudheer 3 

how to use sforce connection

Amit Chaudhary 8Amit Chaudhary 8
Example 1:-
var newRecords = []; 
var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.Voice_Referal__c = true; 
result = sforce.connection.update(newRecords); 
Example 2:-https://success.salesforce.com/answers?id=90630000000gwO5AAI

//Grab the status value you're interested in, and I'm blanking on how to do this at the moment

if(status <> "Particular Value"){
alert("Nice try, think again.");
window.open('/apex/<whatever your page is>');

Example 3:- http://https://success.salesforce.com/answers?id=90630000000CjubAAC

if("{!Contact.New_Hire_Start_Date__c}" !== ""){
    var contactToUpdate = new sforce.SObject("Contact");

    contactToUpdate.Id = "{!Contact.Id}";
    contactToUpdate.Recruiting_Status__c = "NURF Initiated";
    contactToUpdate.Workflow_Trigger_FOR_NURF__c = "1";

    var result = sforce.connection.update([contactToUpdate]);

    if (result[0].success === "false"){
    alert("The New Hire Start Date field has to be checked!");

Example 4:-

Please let us know if this will help you,

Amit Chaudhary
SFDC developer999SFDC developer999
Hi Amit,
  what is the usage of this test : {!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}

  a button is defined with onclick javascript and an email should be sent after button is clicked:

OnClick JavaScript{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
 result = sforce.connection.update([object]);
However email was not sent, where to look at ? where Can I find the connection.js ?
Satya Ranjan MohantySatya Ranjan Mohanty
HI Amit,

Can you please guide me how to implement  this type of functionality in lightning,as you know javascript buttons will not working lightning.

Thanx in advance
Phil Medina 2Phil Medina 2
I will keep it very generic.
1. Create apex class to handle the logic. (validations and checks, actions...)
2. Create new lightning component to display the button.
3. On the controller of the lightning component you created call the class you created in step 1.
     (You are giving the new button direction of what to do when clicked.)
4. Create a new action with action type of lightning component.  Then point to your lightning component name from step 2.
5. Add component to lightning page.