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

Error in Test Class for SOQL Query String Child relationship
Hi All,
I have a batch call out class which has a nested SOQL query string in start method. My test class fails with following:
System.SObjectException: Invalid aggregate relationship Child Relationship Name for Account
my code is below:
I have a batch call out class which has a nested SOQL query string in start method. My test class fails with following:
System.SObjectException: Invalid aggregate relationship Child Relationship Name for Account
my code is below:
global class batchclassname implements Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts { global database.querylocator start(Database.BatchableContext BC) { String Query = 'SELECT id, Industry__c, (Select id, Account_Name__c from Children__r where active__c = true) FROM Account Limit 100'; return Database.getQueryLocator(Query); } global void execute(Database.BatchableContext BC, List<SObject> scope) { if(scope.size()>0) { for(sobject s: scope) { //Get the Account sobject Account a = (Account)s; List<Child__c> RelatedChildren = a.getsobjects('Children__r'); // This line causing issue in test class I believe for(Child__c Ch:RelatedChildren) { do some call out here.... } } } } global void finish(Database.BatchableContext BC) { } }
List<SObject> RelatedRecords = a.getsobjects('Customer_Accounts__r');
List<Customer_Account__c> RelatedAcc = (List<Customer_Account__c>)RelatedRecords;
and then going over the child list...
All Answers
Thanks for your reply.
My child relationship name is Customer_Accounts__r. I have written children__r to make it simpler. Also my child object name is customer__c.
thanks
List<Child__c> RelatedChildren = a.getsobjects('Children__r');
with
List<Child__c> RelatedChildren = a.get(0).getsobjects('Children__r');
The reason I am doing this as it would check for the first element in the List (as Account is also a list )else you can loop around the collection to get the whole list.
Thanks again
List<SObject> RelatedRecords = a.getsobjects('Customer_Accounts__r');
List<Customer_Account__c> RelatedAcc = (List<Customer_Account__c>)RelatedRecords;
and then going over the child list...