function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Homelike DevelopmentHomelike Development 

Best way of querying account history (and related accounts)

I would like to query the account history where I am excluding certain account record types.

I am developing the query in Workbench and am currently using the Workbench SOQL query tab.

As a first step I tried to get the Account.RecordTypeId, but neither of the following worked (after allowing for querying parent-child relationships in settings):
 
SELECT AccountId.RecordTypeId FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId' in field path."
 
SELECT AccountId__r.RecordTypeId FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId__r' in field path."
 
SELECT AccountId.RecordTypeId__r FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId' in field path."

Ultimately I am using the query to get data via the python package Simple Salesforce. Alternative approaches are also welcome.






 
Best Answer chosen by Homelike Development
SarvaniSarvani
Hi,

Sorry my bad, please paste the below query format in the workbench and try.
Select Accountid,
Account.name,
Account.recordtypeId
From Accounthistory where 
account.RecordtypeId!=‘012580000004SxCAAU'
Please refer to the similar link below
https://developer.salesforce.com/forums/?id=9060G000000BdqcQAC

Hope this helps, please mark as solved if it does

Thanks

All Answers

SarvaniSarvani
Hello,

Please try this query for extracting all the accounts and there related activity history records filtered with excluding record type .
SELECT id,name, recordtypeid, (Select Accountid,ActivityDate, Description,whatid,whoid from ActivityHistories) from account where RecordTypeId!='012f4000000S2bNAAS'
Replace your recordtypeid in the query.

Hope this helps! Please mark as best answer if it solves your problem.

Thanks
 
Homelike DevelopmentHomelike Development
SELECT id,name, recordtypeid, (Select NewValue, OldValue from AccountHistory) from account where RecordTypeId!='012580000004SxCAAU' LIMIT 10

Does not work, unfortunately, you are selecting from ActivitiesHistories and not from AccountHistory
SarvaniSarvani
Hi,

Sorry my bad, please paste the below query format in the workbench and try.
Select Accountid,
Account.name,
Account.recordtypeId
From Accounthistory where 
account.RecordtypeId!=‘012580000004SxCAAU'
Please refer to the similar link below
https://developer.salesforce.com/forums/?id=9060G000000BdqcQAC

Hope this helps, please mark as solved if it does

Thanks
This was selected as the best answer
Homelike DevelopmentHomelike Development
Perfect! This works! thank you.

Cheers