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

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

See the Force.com REST API Query reference for online resources.

Query SalesForce Example

The Groovy script example below illustrates using the Query service to retrieve data from the SalesForce server. In this examples configuration Service Parameters are accessed via the serviceParameters map object.

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

 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 Query service
 def sObject = salesForceClient.getQuery()

 // Get a contact with Account details from SalesForce returned as a JSON string - The contact email address is used for the lookup
 def jsonResponseString = query.getOperation("SELECT id,firstname,lastname,phone,email,a.name,a.industry FROM contact c, c.account a WHERE c.email='[email protected]'") 
Since:
3.6.5
  • Constructor Details

    • Query

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

    • getOperation

      public String getOperation(String soql) throws IOException
      Perform the Query GET operation and return the results in a JSON string.

      Groovy Example

      The Groovy script example below illustrates using the Query object to retrieve data 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.Query
      
       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 Query service
       def query = salesForceClient.getQuery()
      
       // Get a contact with Account details from SalesForce returned as a JSON string - The contact email address is used for the lookup
       def jsonResponseString = query.getOperation("SELECT id,firstname,lastname,phone,email,a.name,a.industry FROM contact c, c.account a WHERE c.email='[email protected]'")
      
       // Example of how to use the results to populate an Avoka Transact form in a Prefill service
       Mapinvalid input: '&ltString', Object> responseMap = new JsonSlurper().parseText(jsonResponseString)
       List<Map<String,Object>> recordList = responseMap.records
       def record = recordList.get(0)
      
       def xmlDoc = new XmlDoc(schemaSeed)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/FirstName", record.FirstName)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/LastName", record.LastName)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/Email", record.Email)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/Phone", record.Phone)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/Account/Name", record.Account.Name)
       xmlDoc.setText("/AvokaSmartForm/SalesForceData/Account/Industry", record.Account.Industry)
      Parameters:
      soql - the SalesForce Object Query (required)
      Returns:
      a JSON String representation of the recordset
      Throws:
      IOException - if an error occurs performing the operation