java.lang.Object
com.avoka.component.salesforce.service.SObject

public class SObject extends Object
Provides a SObject SalesForce service class.

See the Force.com REST API SObject Rows reference for online resources.

SObject SalesForce Example

The Groovy script example below illustrates using the SObject service to update a contact on the SalesForce server. In this examples configuration Service Parameters are accessed via the serviceParameters map object, and it is assumed that the SalesForce Object ID of the contact is known.

 import com.avoka.component.salesforce.SalesForceClient
 import com.avoka.component.salesforce.service.SObject

 def username = serviceParameters["SalesForce Username"]
 def passwordToken = serviceParameters["SalesForce Password Security Token"]
 def clientId = serviceParameters["SalesForce Client Id"]
 def clientSecret = serviceParameters["SalesForce Client Secret"]
 def loginServerUrl = serviceParameters["SalesForce Login Server URL"]

 def contactId = serviceParameters["Contact ID"]
 def updateJson = "{""Phone"":""0999999999""}"

 // Create a SalesForce client using the service params with the configured connection details
 def salesForceClient = new SalesForceClient(username, passwordToken, clientId, clientSecret, loginServerUrl)

 // Create a SObject service
 def sObject = salesForceClient.getSObject()

 // Update the Phone Number of the contact
 sObject.patchOperation("Contact", contactId, updateJson)
Since:
3.6.5
  • Constructor Details

    • SObject

      public SObject(SalesForceConnection salesForceConnection)
      Create a new SalseForce REST API SObject object with the given SalesForce connection.
      Parameters:
      salesForceConnection - SalesForce connection context
  • Method Details

    • postOperation

      public String postOperation(String sObjectName, String bodyJsonString) throws IOException
      The POST operation will create a record on the SalesForce server.

      Groovy Example

      The Groovy script example below illustrates using the SObject object to create a contact record on the SalesForce server. In this example configuration Service Parameters are accessed via the serviceParameters array.

       import com.avoka.component.salesforce.SalesForceClient
       import com.avoka.component.salesforce.service.SObject
      
       def username = serviceParameters["SalesForce Username"]
       def passwordToken = serviceParameters["SalesForce Password Security Token"]
       def clientId = serviceParameters["SalesForce Client Id"]
       def clientSecret = serviceParameters["SalesForce Client Secret"]
       def loginServerUrl = serviceParameters["SalesForce Login Server URL"]
      
       def bodyJsonString = "{
           "FirstName": "First",
           "LastName": "Last",
           "Phone": "0999999999",
           "Email": "[email protected]",
           "AccountId": "0019000000QleXDABC"
           }"
      
       // Create a SalesForce client using the service params with the configured connection details
       def salesForceClient = new SalesForceClient(username, passwordToken, clientId, clientSecret, loginServerUrl)
      
       // Create a SObject service
       def sObject = salesForceClient.getSObject()
      
       // Create a new contact in SalesForce. The return value is the Contact ID
       def newContactId = sObject.postOperation("Contact", bodyJsonString) 
      Parameters:
      sObjectName - The name of the SalesForce Object type (required)
      bodyJsonString - JSON String representing the data to insert (required)
      Returns:
      the ID of the new Object created
      Throws:
      IOException - if an IO error occurs
    • getOperation

      public String getOperation(String sObjectName, String id) throws IOException
      The GET operation will retrieve a record from the SalesForce server.

      Groovy Example

      The Groovy script example below illustrates using the SObject object to retrieve a contact record from the SalesForce server. In this example configuration Service Parameters are accessed via the serviceParameters array.

       import groovy.json.JsonSlurper
      
       import com.avoka.component.salesforce.SalesForceClient
       import com.avoka.component.salesforce.service.SObject
      
       def username = serviceParameters["SalesForce Username"]
       def passwordToken = serviceParameters["SalesForce Password Security Token"]
       def clientId = serviceParameters["SalesForce Client Id"]
       def clientSecret = serviceParameters["SalesForce Client Secret"]
       def loginServerUrl = serviceParameters["SalesForce Login Server URL"]
      
       // Create a SalesForce client using the service params with the configured connection details
       def salesForceClient = new SalesForceClient(username, passwordToken, clientId, clientSecret, loginServerUrl)
      
       // Create a SObject service
       def sObject = salesForceClient.getSObject()
      
       // In this example the contact ID is provided as a service parameter. In practice it can be retrieved using a Query object
       def contactId = serviceParameters["Contact ID"]
      
       // Retrieve a contact from SalesForce. The return value is the JSON representation
       def jsonResponseString = sObject.getOperation("Contact", contactId)
      
       // Example of how to use the results to populate an Avoka Transact form in a Prefill service
       Map&ltString, Object> responseMap = new JsonSlurper().parseText(jsonResponseString)
      
       def xmlDoc = new XmlDoc(schemaSeed)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/FirstName", responseMap.FirstName)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/LastName", responseMap.LastName)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/Email", responseMap.Email)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/Phone", responseMap.Phone)
      Parameters:
      sObjectName - The name of the SalesForce object type (required)
      id - The SalesForce Object ID for the object to be retrieved (required)
      Returns:
      a JSON String representation of the object
      Throws:
      IOException - if an IO error occurs
    • patchOperation

      public String patchOperation(String sObjectName, String id, String bodyJsonString) throws IOException
      The PATCH operation will update an existing record on the SalesForce server.

      Groovy Example

      The Groovy script example below illustrates using the SObject object to update a contact record on the SalesForce server. In this example configuration Service Parameters are accessed via the serviceParameters array.

       import com.avoka.component.salesforce.SalesForceClient
       import com.avoka.component.salesforce.service.SObject
      
       def username = serviceParameters["SalesForce Username"]
       def passwordToken = serviceParameters["SalesForce Password Security Token"]
       def clientId = serviceParameters["SalesForce Client Id"]
       def clientSecret = serviceParameters["SalesForce Client Secret"]
       def loginServerUrl = serviceParameters["SalesForce Login Server URL"]
      
       def bodyJsonString = "{
           "Phone": "0988888888"
           }"
      
       // Create a SalesForce client using the service params with the configured connection details
       def salesForceClient = new SalesForceClient(username, passwordToken, clientId, clientSecret, loginServerUrl)
      
       // Create a SObject service
       def sObject = salesForceClient.getSObject()
      
       // In this example the contact ID is provided as a service parameter. In practice it can be retrieved using a Query object
       def contactId = serviceParameters["Contact ID"]
      
       // Update the phone number for the contact
       sObject.patchOperation("Contact", contactId, bodyJsonString)
      Parameters:
      sObjectName - The name of the SalesForce object type (required)
      id - The SalesForce Object ID for the object to be updated (required)
      bodyJsonString - JSON String representing the data to update (required)
      Returns:
      the SalesForce patch operation response
      Throws:
      IOException - if an IO error occurs
    • deleteOperation

      public String deleteOperation(String sObjectName, String id) throws IOException
      The DELETE operation will delete an existing record from the SalesForce server.

      Groovy Example

      The Groovy script example below illustrates using the SObject object to delete a contact record from the SalesForce server. In this example configuration Service Parameters are accessed via the serviceParameters array.

       import com.avoka.component.salesforce.SalesForceClient
       import com.avoka.component.salesforce.service.SObject
      
       def username = serviceParameters["SalesForce Username"]
       def passwordToken = serviceParameters["SalesForce Password Security Token"]
       def clientId = serviceParameters["SalesForce Client Id"]
       def clientSecret = serviceParameters["SalesForce Client Secret"]
       def loginServerUrl = serviceParameters["SalesForce Login Server URL"]
      
       // Create a SalesForce client using the service params with the configured connection details
       def salesForceClient = new SalesForceClient(username, passwordToken, clientId, clientSecret, loginServerUrl)
      
       // Create a SObject service
       def sObject = salesForceClient.getSObject()
      
       // In this example the contact ID is provided as a service parameter. In practice it can be retrieved using a Query object
       def contactId = serviceParameters["Contact ID"]
      
       // Delete the contact from SalesForce
       sObject.deleteOperation("Contact", contactId)
      Parameters:
      sObjectName - The name of the SalesForce object type (required)
      id - The SalesForce Object ID for the object to be deleted (required)
      Returns:
      the SalesForce delete operation response
      Throws:
      IOException - if an IO error occurs