Salesforce query service

Salesforce query service

The Salesforce Query Service can be used to submit SOQL queries to Salesforce. SOQL is an acronym for Salesforce Object Query Language and is a query language developed by Salesforce for retrieving information.

In contrast to SQL, SOQL cannot be used to create, update or delete data. It is only used to retrieve information. If you wish to create, update or delete Salesforce records, you are referred to the Salesforce Create Service, Salesforce Update Producer and Salesforce Delete Producer components, respectively.

The Salesforce Query Service has the option of either statically defining a query during component configuration or extracting the query from the specified ConnectMessagePart.

When extracting the query from a ConnectMessagePart it is assumed that the body consists of a plain text SOQL query.

After executing the query, the result will be stored as XML in the outgoing ConnectMessagePart. For example, after executing the query “SELECT Name FROM Account LIMIT 2” you might expect the following output:

<records>
    <record type=”Account”>
        <field name=”Name” value=”foo”/>
    </record>
    <record type=”Account”>
        <field name=”Name” value=”bar”/>
    </record>
</records>

The top-level element is always records. The records element can have multiple record subelements. Each record always has a type attribute and optionally an id attribute. Furthermore, each record has zero or more fields. Each field must have a name and a value attribute.

The following output is the result of executing the query “SELECT Id, Rating FROM Account LIMIT 2”:

<records>
   <record type=”Account” id=”0013X00002SQA0SQAX”>
       <field name=”Rating” value=”Hot”/>
   </record>
   <record type=”Account” id=”0013X00002SQyy3QAD”>
   </record>
</records>

Note that the id value is added as an attribute to a record and not in the form of a separate field. Furthermore, the rating field is omitted from the second account record because that account has value null for rating. So if the requested field value is null, it is omitted from the output.

When using aggregate SOQL queries the result is still stored in a record element. The type attribute of the record attribute will in this case be “AggregateResult”. The computed value is stored in a field element with the name “expr0”. For example, after executing “SELECT COUNT(Name) FROM Account” we get:

<records>
    <record type=”AggregateResult”>
        <field name=”expr0” value=”42”/>
    </record>
</records>

Finally, see the article on authentication for the different available options as well as their corresponding requirements.