I am creating new case records from the values on custom object record, however it is throwing error for lookup field value. below is my code
global class caseToBe implements Database.Batchable<sObject>, Database.Stateful {
Integer totalRecordsInserted = 0;
Integer totalRecordsFailed = 0;
global Iterable<sObject> start(database.BatchableContext BC)
{
system.debug('Start Called');
return Database.getQueryLocator([select Name,Accounting_Date__c,Balance_Due__c,Temp__c from CaseToBe__c where Name != NULL]);
}
global void execute(Database.BatchableContext BC, List<CaseToBe__c> scope)
{
system.debug('Execute Called');
List<Case> ToInsertCaseList = new List<Case>();
for(CaseToBe__c ctb : scope)
{
system.debug('In Loop');
ToInsertCaseList.add(
new case(
Account_Number__c = ctb.Name,
Balance_Due__c = ctb.Balance_Due__c,
Account = ctb.Agency_Name__c,
Status = 'Working',
Origin = 'Email'));
}
insert ToInsertCaseList;
}
global void finish(database.BatchableContext BC)
{
system.debug('Finish Called');
AsyncApexJob a = [Select Id, Status, NumberOfErrors,JobItemsProcessed, TotalJobItems, CreatedBy.Email
from AsyncApexJob where Id =
:BC.getJobId()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {a.Createdby.Email};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex sharing Recalculation' + a.Status);
mail.setplainTextBody('The Batch Apex Job has been processed' + a.TotalJobItems + 'batches with' + a.NumberOfErrors + 'failures');
Messaging.sendemail(new Messaging.SingleEmailMessage[] {mail});
}
}
Error
Invalid initial expression type for field Account, expecting: Account (or single row query result of that type)