0

For Account, we have few record types. we want to have the related vf page displayed when a specific record type is selected.

However, upon selecting a record type, the below vf page is not directing the VF new record page specific to record type. it is displaying nullpointer exception.

We also have a domain for our instance.

Am i missing something here?

<apex:page standardController="Account" extensions="NewAccountExtension" action="{!redirectToNewVFPage}">
</apex:page>

.

public with sharing class NewAccountExtension {

    public String recordTypeId;

    public NewAccountExtension(ApexPages.StandardController std) {

    }

    public Pagereference redirectToNewVFPage(){
        Pagereference pg = null;
        if(ApexPages.CurrentPage().getParameters().get('RecordType') != null){
            recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');
            if(recordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Finance_Account').getRecordTypeId()){
                pg = new Pagereference('https://avantegrande.cs50.my.salesforce.com/apex/fin_new_account');

            }else if(recordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Logistics_Account').getRecordTypeId()){
                pg = new Pagereference('https://avantegrande.cs50.my.salesforce.com/apex/logi_account');
            }
            pg.setRedirect(true);
            return pg;
        }
        return null;
    }
}
0

Seems that you're having issues when receiving the record type, please double check your record type developer name too, just to make sure you have the correct id. I hope the code below can help you.

public with sharing class NewAccountExtension {

    private ApexPages.StandardController standardController{get; set;}

    public NewAccountExtension(ApexPages.StandardController controller) {
        standardController = controller;
    }

    public PageReference redirectPage(){
        Pagereference pg = null;
        Account record = (Account) standardController.getRecord();
        Id recordTypeId = record.RecordType.Id;
        if(recordTypeId != null){
            if(recordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('TypeA').getRecordTypeId()) {
                pg = new Pagereference('/apex/accountRecordTypeA');

            } else if(recordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('TypeB').getRecordTypeId()) {
                pg = new Pagereference('/apex/accountRecordTypeB');
            }
            pg.getParameters().put('id', record.Id);
            pg.setRedirect(true);
            return pg;
        }
        return null;
    }
}
2
  • Could you add a clear description of what your code paste changed or fixed relative to the original question?
    – David Reed
    Nov 5 '18 at 11:50
  • Thanks Pablo - I have double checked the id's to no avail. the page is not directing to any page after selecting the record type. even when directed to generic sites (google.com) also its not redireting. Nov 5 '18 at 11:57
0

It looks to me like you're calling the wrong Describe API method to get your Record Type Id.

    if(recordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Finance_Account').getRecordTypeId()){

Finance_Account looks like it is probably the Developer Name of the Record Type, not the label. Confusingly, getRecordTypeInfosByName() returns Record Types by the user-visible label. This would return null and trigger your NullPointerException.

To cure this, you can just switch to the new method getRecordTypeInfosByDeveloperName().

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.