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
Jewelyn FregoeJewelyn Fregoe 

I think this Apex class is keeping my users from selecting Opportunity Record type... Can anyone confirm?

So I posted on the SFDC help forums about a problem I'm having where my Opportunity Record Type doesn't seem to stick. I think I've narrowed down the problem to this Apex Class that was already in my SFDC site when I inherited it. Can anyone confirm that's what's happening? Bonus points if you know how to fix it so it allows for different record types to be used! :) 
 
public class NewOpportunityOverrideController
{
    private Opportunity opp;
    
    
    public NewOpportunityOverrideController(ApexPages.StandardController controller)
    {
        opp = (Opportunity) controller.getRecord();
    }



    public PageReference getOverrideURL()
    {
        
        Account acc;
        Opportunity_Prefix__c updateSeq;
        if (opp!=null && opp.AccountId!=null)
        {
          acc = [SELECT Id
                        ,Name
                          ,Opportunity_Prefix__c
                          ,Opportunity_Prefix__r.Name
                          ,Opportunity_Prefix__r.Next_Sequence__c
                     FROM Account
                    WHERE Id=:opp.AccountId];
          // increment seq
          if (acc.Opportunity_Prefix__c!=null)
          {
            updateSeq = new Opportunity_Prefix__c(Id=acc.Opportunity_Prefix__c, Next_Sequence__c=acc.Opportunity_Prefix__r.Next_Sequence__c+1);
            update updateSeq ;
          }
        }
        else
        {
            throw new OpportunityException('::::: Please create opportunities from the Account page :::::');
        }
        
        
        String oppName = 'Please associate account with an Opportunity Prefix';
        
        if (acc!=null && acc.Opportunity_Prefix__c!=null)
        {
            string seq = String.ValueOf(acc.Opportunity_Prefix__r.Next_Sequence__c);
            string paddedSeq = seq.leftPad(3);
            paddedSeq = paddedSeq.replace(' ', '0');
            oppName = acc.Opportunity_Prefix__r.Name + paddedSeq + ' -';
        }
        
        
        return new PageReference('/006/e?opp3='+oppName+'&nooverride=1');
    }

  public class OpportunityException extends Exception {}

}

 
UC InnovationUC Innovation
Hi Jewelyn,

I saw your previous post, and saw that the record type automatically updates to Clinical. Can you check if clinical is the default record type for your profile? I think maybe a new opportunity is being created and is defaulting to the profile's default record type.
Jewelyn FregoeJewelyn Fregoe
Clinical is the default record type. I just changed my default to CIS and it remained CIS when I created the opp. Now if I try to make a Clinical opp, the record type remains CIS. However, I need my users to be able to use any of the record types so they get the appropriate layout depending on the opportunity type. I have all 3 record types available for my profile.

User-added image

Do I have to create the opp and change the record type after creating it every time? That doesn't make sense...  :(
UC InnovationUC Innovation
Could you show me your VF page? Maybe it'll give me some more hints on what's going on.
Jewelyn FregoeJewelyn Fregoe
I've included a screenshot and copied the code for you. Thanks!
User-added image
<apex:page standardController="Opportunity" extensions="NewOpportunityOverrideController" action="{!getOverrideURL}">
  <apex:outputField value="Opportunity.Id"/>
  <apex:outputField value="Opportunity.Name"/>
  <apex:outputField value="Opportunity.AccountId"/>
</apex:page>