You need to sign in to do that
Don't have an account?
sfdc fresher
unable to fetch the contact records while comparing the record id with createddate
hi everyone,
I want to update DOB filed of contact which has data type DATE/TIME by using batch. I have written below code. but am getting below error. could anyone please suggest me.
ERROR: Expecting colon,but found dt1
Could anyone please suggest the query for this and below is my code
global class Sample_Contactupdate_Batch implements Database.batchable<SObject> {
public Datetime CreatedDate {set;get;}
global database.QueryLocator start(Database.BatchableContext jobid)
{
date dt1=date.today();
date dt2=date.valueOf(CreatedDate);
String query='select id,name, DOB__c from Contact where dt2<=dt1';
return database.getQueryLocator(query);
// we can query upto 50 million records
}
global void execute(Database.BatchableContext jobid,list<Contact> scope)
{
List<Contact> ctc=new List<Contact>();
//Contact c=new Contact();
for(Contact c:scope)
{
c.DOB__c = CreatedDate+13;
ctc.add(c);
}
update ctc;
}
global void finish(database.BatchableContext jobid)
{
}
}
I want to update DOB filed of contact which has data type DATE/TIME by using batch. I have written below code. but am getting below error. could anyone please suggest me.
ERROR: Expecting colon,but found dt1
Could anyone please suggest the query for this and below is my code
global class Sample_Contactupdate_Batch implements Database.batchable<SObject> {
public Datetime CreatedDate {set;get;}
global database.QueryLocator start(Database.BatchableContext jobid)
{
date dt1=date.today();
date dt2=date.valueOf(CreatedDate);
String query='select id,name, DOB__c from Contact where dt2<=dt1';
return database.getQueryLocator(query);
// we can query upto 50 million records
}
global void execute(Database.BatchableContext jobid,list<Contact> scope)
{
List<Contact> ctc=new List<Contact>();
//Contact c=new Contact();
for(Contact c:scope)
{
c.DOB__c = CreatedDate+13;
ctc.add(c);
}
update ctc;
}
global void finish(database.BatchableContext jobid)
{
}
}
sfdc fresher
we can achieve it by Last_N_DAYS:13 like this, but i just want to know by converting createdDate(date/time) to date and compare with it to system date....how can we achieve this