You need to sign in to do that
Don't have an account?
Ram_Sfdc
The SOQL query parent record from Child object trigger showing no records
Hi,
I have a visualforce page, through which I am creating a Parent and child record (master-detail relationship). Once the child is created, based on some criteria the child record updates the parent.
In afterInsert of the child object, I have a SOQL query on Parent object and it returns 0 records.
Following is the code that I am using:
Set<Id> setParentIds = new Set<Id>();
for(){
setParentIds.add(child.Parent__c)
}
System.debug(setParentIds); - Works fine and displays Ids of parent Object
List<parent__c> = [Select Id, field__c From parent Where Id IN:setParentIds] - This will get 0 records.
This is totally weird, I am getting Ids in 'setParentIds' Set and when I Query why would the Query show 0 records? Any thoughts! What am I missing here!
I have a visualforce page, through which I am creating a Parent and child record (master-detail relationship). Once the child is created, based on some criteria the child record updates the parent.
In afterInsert of the child object, I have a SOQL query on Parent object and it returns 0 records.
Following is the code that I am using:
Set<Id> setParentIds = new Set<Id>();
for(){
setParentIds.add(child.Parent__c)
}
System.debug(setParentIds); - Works fine and displays Ids of parent Object
List<parent__c> = [Select Id, field__c From parent Where Id IN:setParentIds] - This will get 0 records.
This is totally weird, I am getting Ids in 'setParentIds' Set and when I Query why would the Query show 0 records? Any thoughts! What am I missing here!
Try this -
trigger Test on Child_Accnt__c (after insert) {
Set<Id> setParentIds = new Set<Id>();
for(child_accnt__c ca:trigger.new){
setParentIds.add(ca.ParAccountId__c);
}
System.debug(setParentIds);
List<Account> Accnts = new List<Account>([Select Id, industry From account Where Id IN:setParentIds]);
system.debug(Accnts);
}
It returns results.
Cheers,
Aparna Hegde