When a New button is clicked on Account page we are redirecting some users to Custom VF page and for system admin we are redirecting to the actual record type selection page.

But when System admin is trying to click continue button on record type selection, it is redirecting them to the same page (recordtype selection page) instead of taking them to create new account for selected recordtype.

Class :

public pagereference  method{
    Id userProf = UserInfo.getProfileId();
    Set<Id> profSet = new Set<Id>();
    List<Profile> profDetails = [SELECT Id,
    FROM Profile
    NAME = 'System Administrator'];

    for(Profile profids: profDetails){

    PageReference pageRef;
        pageRef=new PageReference('/setup/ui/recordtypeselect.jsp?ent=Account&retURL=%2F001%2Fo&save_new_url=%2F001%2Fe%3FretURL%3D%252F001%252Fo');
        pageRef = new PageReference('/apex/VFpage');
    return pageRef;
  • The question's answered, but slight suggestion on improving your code: to form Set<Id> profSet you could use Map<Id, Profile> profileMap = new Map<Id, Profile>([SELECT Id, Name FROM Profile ...]); and then instead of profSet.contains(userProf)) use profileMap.keySet().contains(userProf). takes less code for the same result. – EvAzi Feb 7 '17 at 15:57

You have overriden new button so when you navigate in usual way, it would keep on redirecting to same page.

To stop that in Salesforce, we can make use of nooverride query parameter.

So try appending &nooverride=1 in query parameter for System Administrator.


  1. Avoid hardcoding VF page URL, look at Pagereference methods.

    • Use PageReference pr = Page.existingPageName;
  2. Construct new page URL as:

    PageReference pr = new PageReference( '/' + SObjectType.Account.getKeyPrefix() + '/e' ); pr.getParameters().put('nooverride', '1');

  • Thanks for yor response. I added nooverride=1 but only after second attempt it is taking to new account page – Learner Feb 7 '17 at 16:04
  • just navigate to /001/e instead of the hardcoded URL, in your button, you have to disable Skip Record Type Selection Page setting. – Raul Feb 7 '17 at 16:08

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.