I'm trying to get a full list of contracts for all accounts in SF. I've been using a couple of SOQLs with no luck. I'm just getting 0 results:

SELECT id FROM Contract


SELECT id FROM Contract WHERE accountId != null

Perhaps the object "Contract" is incorrect? I'm using this documentation for reference: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contract.htm

Thank you for you help! (I'm new to SF SOQL)

  • Nothing wrong with the query. Perhaps, there is no contract data in the org you are querying?
    – arut
    Commented Aug 31, 2020 at 18:11
  • As a sanity check, are you sure that you have any Contracts at all in the org you're running this query in? Do you have an idea of how many Contracts you're expecting? Are you running this query in a production environment, or is it being run in a sandbox/scratch org?
    – Derek F
    Commented Aug 31, 2020 at 18:11
  • Please edit your post to include more details - Are you in production or a sandbox? What tool are you using? Have you checked your user profile permissions for Contract? Commented Aug 31, 2020 at 19:38

1 Answer 1

SELECT id FROM Contract

If this query is returning 0 results, then you have no contracts in your org. You should verify which object you're actually looking for.

An easy way to do this is to navigate to a record of that object, click the gear, then click Edit Object then on the screen that opens, verify the API name of the object.

Use that API name in place of Contract in your second query. Ensure that this object also has an AccountId field, otherwise replace AccountId with the corresponding Account Lookup on this object.

  • 1
    Found the Issue, the contract object I was looking for was actually a custom object created to contain contracts in the SF instance. It was not the default Contract SF object. Thank you for the help!
    – danny8k
    Commented Aug 31, 2020 at 20:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .