You need to sign in to do that
Don't have an account?
DEV_CG
Unable to fetch the related object field data in batch apex
Select id, firstname, account.name, account.type from contact
i passed this query into start method, when I checked scope list of execute method I couldn't see any files related to account ..how to fetch them
i passed this query into start method, when I checked scope list of execute method I couldn't see any files related to account ..how to fetch them
Sorry for this issue you are facing.
May I request you please post the complete code snippet of what you have tried so that we can look into it and can help you accordingly.
Happy to help further.
Regards,
Nagendra
see the below code, When I exceute batch is unable to recognize the account fileds
global class SampleBatch implements database.Batchable<sobject>{
global string query='select id,firstname,accountID,account.name,account.type,account.industry from contact';
global database.QueryLocator start(Database.Batchablecontext bc)
{
return database.getQueryLocator(query);
}
global void execute(Database.Batchablecontext bc, List<Sobject> scope)
{
List<String> queryFields;
queryFields=new List<String>{'id','firstname','accountId','account.name','account.type','account.industry'};
String csvFileString = '';
for(String fieldName : queryFields)
{
csvFileString = csvFileString+' '+ fieldName;
}
csvFileString=csvFileString.replaceAll(' ',',').replaceFirst(',','')+'\n';
System.debug(csvFileString);
for(SObject obj : scope)
{
String fieldValue='';
for(String fieldName : queryFields)
{
fieldValue = fieldValue +','+ obj.get(fieldName);
System.debug('fieldvalue@@@@@ '+obj.get(fieldName));
}
fieldValue=fieldValue.replaceFirst(',','');
csvFileString = csvFileString + fieldValue + '\n';
}
}
global void finish(Database.Batchablecontext bc)
{
}
}
and I mentioned the Queryfileds manually becoz, I am uable get the queired fields of Sobject dyanamically...