0

I have a vf page that overrides a custom object's New Button. The original purpose for this was to run a custom check in the constructor, if that check passes I want them to be redirected to the New Record page for this object:

 public WasteAssesmentViewRedirect(ApexPages.StandardController controller) {
    System.debug('controller still called');
    this.controller = controller;

if(Constants.RESTRICTED_PROFILE_SET.contains(CommonUtility.getLoggedInUserProfile().Name))
   {
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'You are not allowed to create/edit from Salesforce'));
   }
}

<apex:page standardController="CustomObject__c" extensions="ObjectViewRedirect" showheader="true" action="{!redirect}">
    <apex:pagemessages escape="false"></apex:pagemessages>
</apex:page>

redirect method:

 public PageReference redirect(){
    //fix this to not redirect if the user is fails the above check.
    System.debug('Action redirect to new page02');
    //Get WA prefix
    Map<String,Schema.SObjectType> m = Schema.getGlobalDescribe();
    Schema.SObjectType s = m.get('CustomObject__c');
    Schema.DescribeSObjectResult r = s.getDescribe();
    String waprefix = r.getKeyPrefix();
    //get  REC ID
    String rectypeid = GetRecordType.getRecID('CustomObject__c', 'REc Name');
    System.debug('wa prefix: '+waprefix);
    PageReference pr = new PageReference('/'+waprefix+'/e?RecordType='+rectypeid);
    pr.setRedirect(true);
    return pr;
}

When I click New from anywhere, the page loads continuosly, in the logs I can see this page override getting called over and over why is that ? In the URL I set the object prefix followed by /e. Does that not go to a new record page ? It shouldn't call itself should it ?

0

Had to add nooverride:

PageReference pr = new PageReference('/'+waprefix+'/e?nooverride=1?RecordType='+rectypeid);

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.