My client needs to have the Stage name with a default value, this mean the value should already be there when you click on the New button.
Workflows, Process Builders or Triggers doesn't work because the user will need to set a value for the Stage.
Hacking the URL of the NEW button won't work. I noticed it's possible to override the NEW button with a VisualForce page. I have created one, but I´m still struggling to have the Stage as a default value.
I found some information that it´s required to have a custom controller to set the default value, but I don't know what I´m doing wrong here. I'm new with Visualforce page and APEX code.
<apex:page standardcontroller="Opportunity" extensions="stagePickListController" tabstyle="Opportunity">
<apex:form id="Form">
<apex:sectionHeader title="Opportunity Edit" subtitle="{!if(Opportunity.Id==null,'New Pre-Opportunity',Opportunity.Name)}"/>
<apex:pageBlock mode="edit" id="oppPB" title="Opportunity Edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pagemessages ></apex:pagemessages>
<apex:pageBlockSection id="OpportunityInformation" title="Pre-Opportunity Information">
<apex:inputField value="{!Opportunity.OwnerId}"></apex:inputField>
<apex:inputField value="{!Opportunity.AccountId}" required="true"></apex:inputField>
<apex:inputField value="{!Opportunity.CloseDate}" required="true"></apex:inputField>
<apex:selectList value="{!stage}" size="0">
<apex:selectOptions value="{!Opportunity.StageName}"/>
</apex:selectList>
<apex:inputField value="{!Opportunity.Name}" required="true"></apex:inputField>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
And this is my custom controller
public class stagePickListController {
private final Opportunity opp;
public string stage {get; set;}
public List<SelectOption> lstStages {get; set;}
public stagePickListController(ApexPages.StandardController stdController) {
this.opp = (Opportunity)stdController.getRecord();
}
public stagePickListController(){
stage = 'S0 - Pre-Opportunity';
}
public List<SelectOption> getStages(){
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('S0 - Pre-Opportunity','S0 - Pre-Opportunity'));
options.add(new SelectOption('Qualified','Qualified'));
options.add(new SelectOption('Closed Lost','Closed Lost'));
return options;
}
}