You need to sign in to do that
Don't have an account?
Sharad Jain 9
Apex code to Update custom date field with 60 days
I have to update Custom date field Mydate__c on Custom object X__c by adding 60 days to it. I need to write a apex code to update 20000 records. Can anyone help me how to achieve it.. Please look into this on high priority
Do we need to date 60days from today to this field 'Mydate__c '?
and For update 20000 records,it's better to use batch Apex .
Thanks
Bhargavi.
Fetch records on basis of Lastupdated Field with LIMIT 10000 and run your Script twice. Its not recommended but you can give a try. May be it will work.
Date dt=Date.today();
List<Service_Access__c> Opp=[select id ,Service_End_Date__c from Service_Access__c
where Service_Access_End_Date__c > :dt Limit 1000];
System.debug('List is '+ Opp);
Map<Id,Service_Access__c> ServiceMap=new Map<Id,Service_Access__c>([select id from Service_Access__c]);
for(Service_Access__c acss:Opp){
string accId = (string)acss.get('id');
if(ServiceMap.containskey(accId)){
ServiceMap.get(accId).Service_End_Date__c = acss.Service_End_Date__c.addDays(60);
}
}
update ServiceMap;
You can use the above code for the update.
Thanks
Bhargavi.