Batch Acquisition of Salesforce Customer Data
Stores business partner’s ID and Name inside Salesforce respectively into data items, and stores its communication log in a String type data item.
2016 © Questetra, Inc. (MIT License)
Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • B: Set Sub-Domain (https://{subdomain}.salesforce.com/) *
  • C: Select STRING DATA for Choice IDs (update) *
  • D: Select STRING DATA for Labels (update) *
  • X: Select STRING DATA for Access Log (update)
Script
// OAuth2 config
// Authorization Endpoint URL: https://login.salesforce.com/services/oauth2/authorize
// Token Endpoint URL: https://login.salesforce.com/services/oauth2/token
// Scope: 
// Consumer Key: (Get by Salesforce Connected App screen)
// Consumer Secret: (Get by Salesforce Connected App screen)

//// == 工程コンフィグの参照 / Config Retrieving ==
var oauth2 = configs.get( "conf_OAuth2" );
var subDomain = configs.get( "conf_SubDomain" );
var dataIdC = configs.get( "conf_DataIdC" ); // (returns Number)
var dataIdD = configs.get( "conf_DataIdD" ); // (returns Number)
var dataIdX = configs.get( "conf_DataIdX" ) + ""; // (returns Number)

//// == ワークフローデータの参照 / Data Retrieving ==


//// == 演算 / Calculating ==
var accessLog = "";
var responseJson = "";
var token = httpClient.getOAuth2Token( oauth2 );

var choiseIds = "";
var choiseLabels = "";

try{
  var uri = "https://";
  uri += subDomain;
  uri += ".salesforce.com/services/data/v37.0/query/";

  var response = httpClient.begin()
    .bearer(token)
    .queryParam("q", "SELECT Id, Name from Account")
    .get(uri);
  accessLog += "---GET request--- " + response.getStatusCode() + "\n";
  responseJson = response.getResponseAsString();
  if( response.getStatusCode() == 200 ){
    var jsonObj = JSON.parse( responseJson );
    for( var i = 0; i < jsonObj.records.length; i++ ){
      choiseIds += jsonObj.records[i].Id + "\n";
      choiseLabels += jsonObj.records[i].Name + "\n";
    }
  }
}catch(e){
  accessLog += e.message + "\n";
}
// for Debug
// accessLog += responseJson + "\n";

//// == ワークフローデータへの代入 / Data Updating ==
retVal.put( dataIdC, choiseIds );
retVal.put( dataIdD, choiseLabels );
if( dataIdX !== "" ){
  retVal.put( dataIdX, accessLog );
}

Download

Capture

%d bloggers like this: