tylerzika
3/8/2017 - 6:13 PM

redirect to appropriate vf page when creating a record

redirect to appropriate vf page when creating a record

public PageReference getRedir() {
    // if the record type selected equals 'Referrals'
    // go to the NewReferral VF page
    if (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Referrals').getRecordTypeId()) {
        PageReference pageRef = new PageReference('/apex/NewReferral');
        pageRef.setRedirect(true);
        return pageRef;    

    } else {
    // else go to the standard opportunity page   
        PageReference pageRef = new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType=' + ApexPages.currentPage().getParameters().get('RecordType') + '&ent=Opportunity');
        pageRef.setRedirect(true);
        return pageRef;      
    }

}