Updating a Record in Salesforce from Google Script Using Rest API
Create connected app with oauth scope to full access
authenticateSF1() method returns the access token required for Rest API Call
updatelead() method gets token as input parameters
function authenticateSF1(){
var url = ‘https://login.salesforce.com/services/oauth2/token’;
var payload = {
‘grant_type’:’password’,
‘client_id’:’please enter your client id’,
‘client_secret’:’please enter your client secret’,
‘username’:’please enter your username’,
‘password’:’please enter your password+securitytoken’
};
var options = {
‘method’:’post’,
‘payload’:payload
};
var response = UrlFetchApp.fetch(url, options);
var result = JSON.parse(response.getContentText());
var token_response = result.access_token;
updatelead(token_response);
}
function updatelead(token_response)
{
var token =token_response;
var baseUrl=’https://na88.salesforce.com’;
var LeadId=’00Q1Y00001mU863′;
var url = baseUrl + ‘/services/data/v41.0/sobjects/Lead/’+LeadId;
var leadinfo = {
‘Hinkle_System_Scheduled__c’ :’True’
};
var leadinfoJson = JSON.stringify(leadinfo);
var option={
‘method’:’patch’,’muteHttpExceptions’: true,
‘headers’: {
‘Authorization’: ‘Bearer ‘+token,
‘Content-Type’: ‘application/json’
},
‘payload’:leadinfoJson,
};
var response = UrlFetchApp.fetch(url, option);
Logger.log(‘result’+JSON.stringify(result));
}