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

Issue in batch class writing
HI All,
I have created a batch class below in which CONTACT is parent object and alu_Application__c is a child object the retion field name is Applicant__c, I need to update the value of contact Prefered Name with alu_Application__c Prefered Name. I tried to excutethe same but it's not working.
global class ContactUpdate implements Database.Batchable<sObject>
{
global string query;
global Database.QueryLocator start(Database.BatchableContext BC)
{
system.debug('Check1');
query = 'SELECT Id,Preferred_Name__c, Applicant__c FROM alu_Application__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<alu_Application__c> scope)
{
system.debug('scope'+scope);
try
{
List<Contact> appCon = new List<Contact>();
for (alu_Application__c ap : scope)
{
system.debug('ap'+ap);
Contact con = new Contact();
con.Id = ap.Applicant__c;
con.Preferred_Name__c = ap.Preferred_Name__c;
appCon.add(con);
}
system.debug('appCon'+appCon);
if(appCon.size() > 0)
{
update appCon;
system.debug('appCon'+appCon);
}
}
catch(Exception e)
{
system.debug('Error ');
}
}
global void finish(Database.BatchableContext BC)
{
system.debug('Check');
}
}
Please helip me ASAP, It's really an urgent task for me!
Thanks,
I have created a batch class below in which CONTACT is parent object and alu_Application__c is a child object the retion field name is Applicant__c, I need to update the value of contact Prefered Name with alu_Application__c Prefered Name. I tried to excutethe same but it's not working.
global class ContactUpdate implements Database.Batchable<sObject>
{
global string query;
global Database.QueryLocator start(Database.BatchableContext BC)
{
system.debug('Check1');
query = 'SELECT Id,Preferred_Name__c, Applicant__c FROM alu_Application__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<alu_Application__c> scope)
{
system.debug('scope'+scope);
try
{
List<Contact> appCon = new List<Contact>();
for (alu_Application__c ap : scope)
{
system.debug('ap'+ap);
Contact con = new Contact();
con.Id = ap.Applicant__c;
con.Preferred_Name__c = ap.Preferred_Name__c;
appCon.add(con);
}
system.debug('appCon'+appCon);
if(appCon.size() > 0)
{
update appCon;
system.debug('appCon'+appCon);
}
}
catch(Exception e)
{
system.debug('Error ');
}
}
global void finish(Database.BatchableContext BC)
{
system.debug('Check');
}
}
Please helip me ASAP, It's really an urgent task for me!
Thanks,
All Answers
Contact con = new Contact();
con.Id = ap.Applicant__c;
TO
Contact con = new Contact(Id = ap.Applicant__c);
Let me know if you face same problem.
Hello Pradeep,
Thanks for the quick response, But I am still facing the same issue.
It's saying completed without any failuer.