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
Chirag MehtaChirag Mehta 

Method to update Opportunity to Next STAGE

Is there any method in Apex which allows to move a selected opportunity to next stage.

 

Something like

opportunity o = [Select Id from Opportunity where Id ='asdsdasd' limit 1]; o.StageName = o.nextStage(); update o;

 

OnkiOnki
opportunity o = [Select Id from Opportunity where Id ='asdsdasd' limit 1];
 
Schema.DescribeFieldResult F = Opportunity.StageName.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();
 
for(Integer i=0;i<P.size();i++)
{
    if(p[i].getValue() ==o.StageName)
   
    o.StageName = p[i+1].getValue();
}
 
Check also if index is last element is should be update with first Element. 
Hope it will solve your problem. 
Message Edited by Onki on 02-14-2010 03:23 AM
Doug ACFDoug ACF
The trick here is defining what you mean by "next".  The OpportunityStage object includes a SortOrder field.  So if your stages are sorted in the correct order you can go off of that field.  Also since the stage list includes inactive values and closed stages, include the Active=True and Closed=False in your query.
Chirag MehtaChirag Mehta
Schema.DescribeFieldResult optyDescribe = Opportunity.StageName.getDescribe(); 
List<Schema.PicklistEntry> optyPickListEntry = optyDescribe.getPicklistValues();

 

Above code does help to retrieve the Stages, but how do i pass information of the BusinessProcess/RecordType for which i need the stages.

 

My requirement is to promote or demote an opportunity based on RecordType(Business Process) to which it belongs.

 

For eg., Suppose there are two opportunity record types (having diff stages) so when i click on promote, it should automatically determine the record type(business process) of opportunity and accordingly promote it to respective stage.

Message Edited by Chirag Mehta on 02-18-2010 02:46 AM
kyle.tkyle.t

Did you ever have any success with this?  I have been unable to find the link between business processes and stages.  I don't know if it is exposed to the API or not.

Chirag MehtaChirag Mehta

no luck yet! After that I moved to different project, so didn't dwelled in later.