+ Start a Discussion
Nishad BashaNishad Basha 

How to query all the account created before 10 days and update their names in salesforce?

How to run the schedule Apex job before 10 days.How to solve the above solution please give some ideas.
Best Answer chosen by Nishad Basha
viruSviruS
Hi Nishad,

Try below 

date d = system.today().addDays(-10);

list<Account> accUpdateList = new list<Account>();
for(Account acc : [select id, name  from account where createdDate = :d]){
    acc.name = 'New Name';
    accUpdateList.add(acc);
}

if(!accUpdateList.isEmpty()){
   update accUpdateList;
}

All Answers

viruSviruS
Hi Nishad,

Try below 

date d = system.today().addDays(-10);

list<Account> accUpdateList = new list<Account>();
for(Account acc : [select id, name  from account where createdDate = :d]){
    acc.name = 'New Name';
    accUpdateList.add(acc);
}

if(!accUpdateList.isEmpty()){
   update accUpdateList;
}
This was selected as the best answer
Nishad BashaNishad Basha
Hi, viruS
here iam asking the schedule apex class using query all the account created before 10 days and update their names
 
viruSviruS
Create One Batch Class and a Schedule using scheduler for the time you wants to execute
Nishad BashaNishad Basha
Hi, viruS
can you give me the example of scheduler class and add above code.please give  the entire  example code.


 
viruSviruS
skypeId
Nishad BashaNishad Basha
Hi, viruS
How to update the Account Names using Batch Apex before 10 days.how to solve above scenario please give some ideas.
viruSviruS
Nishad,

Please go through 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm