function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Balasubramani DhanapalBalasubramani Dhanapal 

opportunities close date as today()?

Hi all, 
           I am beginer of salesforce.Please any one help me  the following code implementation. how to Write Apex class to update all the opportunities close date as today()?

Thanks in advance
Best Answer chosen by Balasubramani Dhanapal
Apoorva SharmaApoorva Sharma
List<Opportunity> opplist=[select closedate from Opportunity];
for(Opportunity opp: opplist){
opp.closedate=date.today();
}
database.update(opplist,false)
 

All Answers

PrakashbPrakashb
Hi,

If you want to update your existing opportunities you can use data loader to update all your existing opportunities.

Any reason you need apex code implementation?

if you need to update all existing opportunities one time without data loader then you can write a  code in Developer console to update opportunities.

Thanks
Prakash 
Chitral ChaddaChitral Chadda
Declare variable as follows:
Date Tdate = System.today();

next do this,
opp.CloseDate= Tdate;
it wud work for you.
Apoorva SharmaApoorva Sharma
List<Opportunity> opplist=[select closedate from Opportunity];
for(Opportunity opp: opplist){
opp.closedate=date.today();
}
database.update(opplist,false)
 
This was selected as the best answer
Oleg NikitchukOleg Nikitchuk
How would you write this if it was a method? Let's say a method that receives List of opportunities and sets their closedate to today?
List<Opportunity> opplist=[select closedate from Opportunity];
for(Opportunity opp: opplist){
opp.closedate=date.today();
}
database.update(opplist,false)