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
mng0827mng0827 

Record type selection visualforce page

Hi,

I would like to create a visualforce page to customize the standard Opportunity record type selection page based on the Account's record type. For example,
Account record type = A, the Opp record type selection should only show opp record types 1,2;
Account record type = B, the Opp record type selection should only show opp record types 3,4

Can someone provide a sample code for me to start with?
EnreecoEnreeco
It is simpler than you think, I'll give you some hints.
1) Create a VF page with a StandardController of type "Account" (so you can add it to your Accountn layout)

2) Get all the recordtypes
Select Id, DeveloperName, Name From RecordType Where SObjectType = 'Opportunity'
3) Filter the recordtypes on point 2) based upon the Account.RecordTypeId or DeveloperName with a logic you own. For example you can create a Map that maps Account Recordtypes to Opportunity RecordTypes
Map<String,List<String>> mapping = new Map<String,List<String>>();
mapping.put('AccountRT1', new List<String>{'OppRT1', 'OppRT2'});
mapping.put('AccountRT2', new List<String>{'OppRT1', 'OppRT3'});
mapping.put('AccountRT3', new List<String>{'OppRT1', 'OppRT2', 'OppRT3'});
And then filtering the query:
List<RecordType> rTypeList = [Select Id, DeveloperName, Name From RecordType Where SObjectType = 'Opportunity' and DeveloperName IN (:mapping.get(currentAccount.RecordType.DeveloperName)];
Now you can create a SelectOption list with all the recordtype you need.

This is a possibile implementation, you can also use an SObject to store the AccountRT/OpportunityRT association of a list custom setting to do it more configurable.


--
May the Force.com be with your


Ramu_SFDCRamu_SFDC
+1 to Forcel Logic

you can also review the below post that talks about replacing a standard record type selection page to custom
 https://developer.salesforce.com/forums/ForumsMain?id=906F000000095W3IAI (http://https://developer.salesforce.com/forums/ForumsMain?id=906F000000095W3IAI)
mng0827mng0827
Thanks everyone! I've tried to compose a code for this but came up with this error:

Variable does not exist: currentAccount.RecordType.DeveloperName

Here's my code:

public class myController {

public list<SelectOption> getRecordTypes()

{
    list<SelectOption> options = new list<SelectOption>();
    for(RecordType sRecordType : [Select Id, DeveloperName, Name From RecordType Where SObjectType = 'Opportunity']){
   
        Map<String,List<String>> mapping = new Map<String,List<String>>();
        mapping.put('Small_Medium_Sized_Business', new List<String>{'Defined_Benefit_Retirement','Defined_Contribution_Retirement'});
       
     List<RecordType> rTypeList = [Select Id, DeveloperName, Name
                                   From RecordType
                                   Where SObjectType = 'Opportunity' and DeveloperName
                                   IN :mapping.get(currentAccount.RecordType.DeveloperName)];
    }
    return options;
}
}