SalesForceRestClient is a client tool component which makes it easy to invoke SalesForce REST APIs.
Most properties of SalesForceRestClient are configured with default values such as SalesForce REST API URLs. Those properties can be configured by yourself and some security related properties should be configured for yourself or your organization. Here are properties list you can configure:
Property | Type | Description | Example value | Default value | |
---|---|---|---|---|---|
connectionInfo | org.onehippo.forge.sforcecomps.client.rest.SalesForceConnectionInfo | SalesForce REST API Connection Info Object | |||
baseUrl | java.lang.String | SalesForce REST API Base URL | https://na9.salesforce.com | https://na1.salesforce.com | |
authTokenPath | java.lang.String | SalesForce oAuth Token Request URL Path | /services/oauth2/token | /services/oauth2/token | |
baseServicesDataPath | java.lang.String | SalesForce Data Services URL Path | /services/data | /services/data | |
baseServicesDataEnvPath | java.lang.String | SalesForce Data Services Environment URL Path | /services/data/v22.0 | /services/data/v20.0 | |
clientId | java.lang.String | The Client ID to connect to SalesForce REST API | 3MVG9lKcPoNINVBJSoQsNCD.HHDdbugPsNXwwyFbgb47KWa_PTv | ||
clientSecret | java.lang.String | The Client Secret to connect to SalesForce REST API | 5678471853609579508 | ||
username | java.lang.String | The username to connect to SalesForce REST API | tester@onehippo.org | ||
password | java.lang.String | The password to connect to SalesForce REST API | password | ||
securityToken | java.lang.String | The Security Token to connect to SalesForce REST API | hhWVl82SHphnA50OTBt2DAZk |
Here is an example on how to create and initialize SalesForceRestClient component in Java code:
SalesForceConnectionInfo connectionInfo = new SalesForceConnectionInfo(); connectionInfo.setClientId("3MVG9lKcPoNINVBJSoQsNCD.HHDdbugPsNXwwyFbgb47KWa_PTv"); connectionInfo.setClientSecret("5678471853609579508"); connectionInfo.setUsername("tester@onehippo.org"); connectionInfo.setPassword("password"); connectionInfo.setSecurityToken("hhWVl82SHphnA50OTBt2DAZk"); SalesForceRestClient client = new SalesForceRestClient(); client.setConnectionInfo(connectionInfo); // Establish access token now; after establishing you can use other methods without authorization. client.establishAccessToken();
Here's an example of how to create an Account record by using simple JSON objects.
JSONObject json = JSONObject.fromObject("{ \"Name\": \"test\" }"); JSONObject jsonObject = client.createRecord("/sobjects/Account", json); System.out.println("Created object: " + jsonObject); // Now you can get the ID of the created account record. String id = jsonObject.getString("id");
Here's an example of how to create an Account record by using simple JSON objects.
JSONObject jsonObject = client.getObjectsFromResourcePath("/sobjects/Account/12345/"); System.out.println("Retrieved object: " + jsonObject);
Here's an example of how to create an Account record by using simple JSON objects.
client.updateRecord("/sobjects/Account/12345/", JSONObject.fromObject("{ \"BillingCity\" : \"San Francisco\" }")); jsonObject = client.getObjectsFromResourcePath("/sobjects/Account/12345/"); System.out.println("Updated Object: " + jsonObject);