0

I am working on a VF page to create an Opportunity from custom related List button on Opportunity itself. My requirement is to pre-populate some fields from original opportunity to child opportunity, which I am fine. However we also need to consider record type and show the stages as per record type. As I am querying the Original opportunity based on Id comes from URL, how can I restrict the stage values based on record type?

Class:

public class tenPageSizeExt {

    public List<Case> results {get;set;}
    public String filterId {get;set;}
    private Id accountId;

    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Open', 'Open'));
        options.add(new SelectOption('Closed', 'Closed'));
        options.add(new SelectOption('All', 'All'));
        return options;
    }
    public Opportunity opp{get;set;}
    public Opportunity opp2{get;set;}
    public Opportunity opp1{get;set;}
    public String oName{get; set;}
    public ApexPages.StandardSetController controller;
    public tenPageSizeExt(ApexPages.StandardSetController qcontroller) {
    getItems();
        //controller.setPageSize(10);
        this.controller = qcontroller;
        Id parentId = ApexPages.currentPage().getParameters().get('Id');
        opp1 =[SELECT Id,
                      Name,
                      StageName,
                      CloseDate,
                      Amount,
                      OwnerID,
                      Original_Opportunity__c,
                      Site__c,
                      Donor_Account__c,
                      Secondary_Opportunity_Owner__c,
                      Donor_Contact__c,
                      Payment_Contact__c,
                      Payment_Account__c,
                      Site_Location__c,
                      Budgeted__c, 
                      Soft_Payment_Credit__c,
                      Account_Soft_Payment_Credit__c,
                      CampaignId,
                      Honoree_Name__c,
                      Media_Campaign__c,
                      Probability,
                      Type,
                      Date__c,
                      Number_of_Times_Acknowledgement__c,
                      Donor_Advised_Fund__c
                      from Opportunity where Id=:parentId LIMIT 1];  
        opp2=New Opportunity();
        opp2.Name =opp1.Name+' Payment';
        opp2.StageName='Posted';
        opp2.Amount=opp1.Amount;
        opp2.CloseDate=opp1.CloseDate;
        opp2.Original_Opportunity__c=opp1.Id;
        opp2.Payment_Contact__c=opp1.Donor_Contact__c;
        opp2.Payment_Account__c =opp1.Donor_Account__c;
        opp2.OwnerID= opp1.OwnerID;   
        opp2.RecordtypeID= opp1.RecordtypeID;  
        opp2.Probability= 100;  

    }

     public PageReference InserrtOpp()
    {
        try{
        insert opp2;
        }catch(exception e)
        {
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'my error msg '+ e);
        ApexPages.addMessage(myMsg);

        }
        PageReference cancel = controller.cancel();
        controller.save();
        return cancel;
    }


}

Screenshot: enter image description here

How can I show the Stage values only relevant to specific record type?

  • Is your button/page bypassing the recordtype selection screen? How is the StageName field currently being represented on the page? – Thomas Taylor Oct 26 '16 at 16:10
  • Yes, it is bypassing the record type selection. Currently the picklist values are populating as per the default record type. – Ajay Oct 26 '16 at 16:14
  • So, the screenshot is of opp2, and the StageName picklist is that of a sales process other than the one belonging to opp1's RecordType? – Thomas Taylor Oct 26 '16 at 16:22
  • Yes, opp2 is new record and the StageName is belongs to opp1's recordtype. – Ajay Oct 26 '16 at 16:35
  • Is there a way we can change the default record type for the VF page? may be a dumb question:) – Ajay Oct 26 '16 at 17:14
0

The code as posted is assigning opp1's record type to opp2. And so opp2 will use the Sales Process assigned to that record type. You need to assign the correct record type to opp2 in order for it to have the correct Sales Process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.