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
vasuroyvasuroy 

calcualte users opportunity

Hi , i need to calculate the toal amount for closed/won opportunity amount for a particular user and display it in a field of custom object , where the custom object has look up relationship to the user, can any one help me how to do that

Best Answer chosen by Admin (Salesforce Developers) 
:) :) :) :) :):) :) :) :) :)

 

//(User) Kevin Peterson ==> 005d0000001TaWw (user ID)

 

Public List<Opportunity> closedWonAmountList = new List<Opportunity>();

Public Double TotalClosedWonAmount;

 

 

closedWonAmountList = [select Amount from opportunity where StageName='Closed Won' AND OwnerID = '005d0000001TaWw' ];


for(Opportunity opp : closedWonAmountList){

       TotalClosedWonAmount = TotalClosedWonAmount + opp.Amount;

}

 

System.debug('Total Closed Won Amount of Kevin Peterson  = ' +TotalClosedWonAmount );

All Answers

:) :) :) :) :):) :) :) :) :)

 

//(User) Kevin Peterson ==> 005d0000001TaWw (user ID)

 

Public List<Opportunity> closedWonAmountList = new List<Opportunity>();

Public Double TotalClosedWonAmount;

 

 

closedWonAmountList = [select Amount from opportunity where StageName='Closed Won' AND OwnerID = '005d0000001TaWw' ];


for(Opportunity opp : closedWonAmountList){

       TotalClosedWonAmount = TotalClosedWonAmount + opp.Amount;

}

 

System.debug('Total Closed Won Amount of Kevin Peterson  = ' +TotalClosedWonAmount );

This was selected as the best answer
vasuroyvasuroy

perfect ,

 


Thanks a lot Ketan