You need to sign in to do that
Don't have an account?

Nested SOQL from child to parent
I need to get the actual Parent ID from the Account object while querying a custom child object.
I have an existing soql that looks like this...
// Build IDNumber list
Map<String,ID_Number__c> IDNumbers = new Map<String,ID_Number__c> (
[select ID__c, Parent_Rate__c ),
from ID_Number__c
Where ID__c IN :idsToQuery] );
When I try this - I get an "enexpected token; 'from' error...
Map<String,ID_Number__c> IDNumbers = new Map<String,ID_Number__c> (
[select ID__c, Parent_Rate__c ), (Select Parent, from Account),
from ID_Number__c
Where ID__c IN :idsToQuery] );
Any guidance?
Thanks!
Try,
Select customAccountid, customobjectfield2, account__r.parentid from Customobject where customAccountid = account__r.id
where account__r is the relationship name from Custom Object to Account.
Also please check below link: which can help you in forming the Queries for the requirment.
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_soql.htm
All Answers
hi,
What is idsToQuery referring too?Also to get the Parent ID from the Custom Child Object you need to use the Relationship to Query the corresponding Parent Id.
Thanks.
the idsToQuery is a set that I'm building so my trigger will run in buld.
So, the custom object has the Account ID on it (the custom is a Master-Detail(Account) ).
So would the subquery be (select Parent, from Account where Account.ID = ID_Number__c.Account ) ?
You have a comma after Parent in (Seleect Parent, from Account)
Try,
Select customAccountid, customobjectfield2, account__r.parentid from Customobject where customAccountid = account__r.id
where account__r is the relationship name from Custom Object to Account.
Also please check below link: which can help you in forming the Queries for the requirment.
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_soql.htm
Thanks!