You need to sign in to do that
Don't have an account?
Jewelyn 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 {} }
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.
Do I have to create the opp and change the record type after creating it every time? That doesn't make sense... :(