• Jhanawa
  • NEWBIE
  • 0 Points
  • Member since 2019
  • VP Tech

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,
My script was running for about a week, I changed the triggers to run less frequently (1x day) so the session was expired.
I added the RefreshToken to it and it's not working and I'm not sure why.
My connected app has the following Scopes:
Access your basic information (id, profile, email, address, phone)
Access and manage your data (api)
Provide access to your data via the Web (web)
Perform requests on your behalf at any time (refresh_token, offline_access)

The app authenticates no problem when I run it manually and connect, so I know the connected App works.

When I view the refreshToken in the log, I can see it, so I know it is stored.

function refreshToken() {
  var props = PropertiesService.getUserProperties();
  var uProps = JSON.parse(props.getProperties()['oauth2.salesforce']);  // assumes the service's name is "salesforce" (set when service was created)
  Logger.log(uProps.refresh_token);
  var sProps = PropertiesService.getScriptProperties();
  var clientId = sProps.getProperty('sfConsumerKey');
  var clientSecret = sProps.getProperty('sfConsumerSecret');
   var response = UrlFetchApp.fetch('login.salesforce.com/services/oauth2/token?grant_type=refresh_token&client_id=' + clientId + '&client_secret=' + clientSecret + '&refresh_token=' + uProps.refresh_token, {method: 'POST'});
  var nuProps = JSON.parse(response);
  uProps.signature = nuProps.signature;
  uProps.access_token = nuProps.access_token;
  uProps.issued_at = nuProps.issued_at;
  props.setProperty('oauth2.salesforce', JSON.stringify(uProps));
  //Logger.log(nuProps);
}
Returned "Undefined" when using Google apps script to downloading Account data from Opportunity. Please help me to get proper record from Field "Account.Name".

Copied following method.
https://gist.github.com/stomita/990589

Modified as followings:

from: Opportunity
fields: Id,Account.Name

----
// Query account data from Salesforce, using REST API with OAuth2 access token.
  var fields = "Id,Account.Name";
  var soql = "SELECT "+fields+" FROM Opportunity LIMIT 100";
  var queryUrl = instanceUrl + "/services/data/v21.0/query?q="+encodeURIComponent(soql);
  var response = UrlFetchApp.fetch(queryUrl, { method : "GET", headers : { "Authorization" : "OAuth "+accessToken } });
  var queryResult = Utilities.jsonParse(response.getContentText());
----