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
Semira@gmail.comSemira@gmail.com 

Unable to Access Page

Hi, I have this piece of code running. I'm trying to set the record type of a child object by using condition to look at a field value of parent.

Eg. Job division = content, Recordtype of work order = restoration.
       job division = other, Recordtype of work order = environmenta.

I have this in my pagereference but the parameter does not run correctly. I'm not sure how else should I be defining the parameters. 
 
public PageReference redirect(){
        
        String prefix = Work_Order__c.SObjectType.getDescribe().getKeyPrefix();
        String param = getParameters()+'&RecordType={!IF(Ispickval(Job_Number__c.Division__c,content),012Q00000000kxB,012Q00000000kxG)}';
        return new PageReference('/'+prefix+'/e?nooverride=1&'+param); 
    }

This is the error I'm getting:

Unable to Access Page
The value of the "id" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information. 

 
Best Answer chosen by Semira@gmail.com
Mohit Bansal6Mohit Bansal6
Hi Semira

Please refer below code.

In this line,    
       
if(Job_Number__r.Division__c=='content')

replace Job_Number__r with the instance of Job_Number.
 
public PageReference redirect(){
        
        String prefix = Work_Order__c.SObjectType.getDescribe().getKeyPrefix();
        String param ='';
        if(Job_Number__r.Division__c =='content')
               param = '012Q00000000kxB';
        else
               param = '012Q00000000kxG';
     
        return new PageReference('/'+prefix+'/e?nooverride=1&RecordTypeID='+param); 
    }

Regards
Mohit Bansal


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

All Answers

Mohit Bansal6Mohit Bansal6
Hi Semira

Please refer below code.

In this line,    
       
if(Job_Number__r.Division__c=='content')

replace Job_Number__r with the instance of Job_Number.
 
public PageReference redirect(){
        
        String prefix = Work_Order__c.SObjectType.getDescribe().getKeyPrefix();
        String param ='';
        if(Job_Number__r.Division__c =='content')
               param = '012Q00000000kxB';
        else
               param = '012Q00000000kxG';
     
        return new PageReference('/'+prefix+'/e?nooverride=1&RecordTypeID='+param); 
    }

Regards
Mohit Bansal


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
This was selected as the best answer
Semira@gmail.comSemira@gmail.com
Thank you. Works like a charm.