Querying Salesforce

Learn how to write SOQL queries to pull SFDC data into Pocus.

Pulling Data from Salesforce

To grab data from Salesforce directly, Pocus uses the Salesforce API with Salesforce’s own query language - SOQL. It’s like SQL, but with some missing functionalities and intricacies. If you’re unfamiliar, leverage the Salesforce documentation to learn more. This guide will give you some quick tips but is by no means exhaustive.

SELECT Id, APIName, Name, BillingCity, Custom_field__c
FROM Contacts

Object

Declare the object you want to pull from with a, you guessed it, FROM. Default objects are plural and CamelCase (Contacts, Accounts, Opportunities, CampaignMembers) and custom objects have an __c at the end (e.g., Workspaces__c).

Fields

Declare the fields you want to pull in by using their API Names.

  • Default Fields
    • Default SFDC fields are CamelCase
  • Custom Fields
    • Custom SFDC fields are Snake_Case with an appended __c - yep that is 2 underscores!
  • Relationship Fields
    • Salesforce objects have relationships to one another via lookup fields. If one object has a lookup field on another, you can pull fields from that nested object into the current one you are querying, this should work up to 3 levels of nesting for example
      • Contact → Account → User
    • The contact object has a lookup to the account, which in turn has a lookup to a Salesforce user that is the owner of the Account. If you are on the contact query and would like to pull in the email of the User that owns the Account with which a contact is associated, you can do this by querying for Account.Owner.Email on the Contact.
    • If you were on the Account, instead of querying OwnerId which would be jdh2738djjsj, you can just do Owner.Email
    • Other common examples, Opportunity.CloseDate
    • You can do the same with custom relationship/lookup fields with one little trick. Change the __c to a __r
      • For example, if there is a custom ownership field Customer_Success_Owner__c that is returning a Salesforce Id jdh2738djjsj query for Customer_Success_Owner__r.Name or Customer_Success_Owner__r.Email to get the Name or Email of the Customer Success Owner.