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
@anilbathula@@anilbathula@ 

how to redirect to standard page

Hi all,

 

iam facing problem using visual force page in my lead there a re four record types

one,two,three,four.

if i click new button->then it shows the record type selection page->then i select one ->it redirects to a visual force page name leadTest. because i over ridden new button with visual force page.

 

if i click two it should go to a standard page record type for two and a page layout is also assigned for it.

 

if i click three it should go to a standard page record type for three and a page layout is also assigned for it.

 

same like for four.

 

but here it is not redirecting to the standard page when iam passing the url in my controller .

 

can any help me. my code is:-

 

visualforce page  

<apex:page StandardController="Lead" tabStyle="Lead" extensions="LeadController" action="{!redirectToPage}" >

 

Controller Method

 public PageReference redirectToPage() {
     
        String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
        if (selectedRecordType == 'One')// id will be there
            return Page.LeadTest.setRedirect(True);        
        else if(selectedRecordType == 'Two')
            return  new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O00000000Acd&ent=Lead');
          else if(selectedRecordType == 'Three')
            return  new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O00000000Acn&ent=Lead');

         else if(selectedRecordType == 'four')
            return  new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O000000003ds&ent=Lead');   
        else
            return null;
    }

Best Answer chosen by Admin (Salesforce Developers) 
@anilbathula@@anilbathula@

Thanks guys finally i found out solution with the help of my colleague Anoop.

 

 public PageReference redirectToPage() {
   
        String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
        Id id=selectedRecordType;
        
        String csRtId=RIIUtility.getRecordTypeId('Home Loan',new Lead());
        String carRtId=RIIUtility.getRecordTypeId('Car Loan',new Lead());               
        String crRtId=RIIUtility.getRecordTypeId('Credit Card',new Lead());
       
        
        if (selectedRecordType == csRtId){
            return Page.LeadTest.setRedirect(True);
            }
       
        if(id == carRtId) {
            PageReference p = new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType='+carRtId+'&ent=Lead ');
            p.getParameters().put('nooverride','1');
            return p;
         }  
       
        if(id == crRtId)  {
            PageReference p = new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType='+crRtId+'&ent=Lead ');
            p.getParameters().put('nooverride','1');
            return p;
         }      
     
                  
        else
            return null;
    }

All Answers

SRKSRK

Add the parameter nooverride
p.getParameters().put('nooverride','1');

 

Code For ref.

 

else if(selectedRecordType == 'Two')

{

p = new PageReference(/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O00000000Acd&ent=Lead'); 
p.getParameters().put('nooverride','1');

return p;

}

else if(selectedRecordType == 'Three')

{

p = new PageReference(/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O00000000Acn&ent=Lead'); 
p.getParameters().put('nooverride','1');

return p;

}

else if(selectedRecordType == 'Four')

{

p = new PageReference(/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O000000003ds&ent=Lead'); 
p.getParameters().put('nooverride','1');

return p;

}

 

 

@anilbathula@@anilbathula@

Hi SRK

 

 i used ur code but it is not going to the standard page it still showing the visual force page .

 is this the problem with over ridding the new button with that visual force page.

 

Thanks

Anil.B

 

SRKSRK

Hi

Can you plz.. share the new code
as you mention that you add the  ('nooverride', '1').

& yes it is bcoz of overrind new button but    nooverride = 1 is parameter is used to overcome the overriding

@anilbathula@@anilbathula@

Hi SRK

 

     This is my code :-

 

 

   
    public PageReference redirectToPage() {
   
      
        String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
        if (selectedRecordType == 'One')
            return Page.LeadTest.setRedirect(True);       
        else if(selectedRecordType == 'Two')  {
            PageReference p = new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType=012O000000003ds&ent=Lead'); 
            p.getParameters().put('nooverride','1');
            return p;       
        }
        else
            return null;
    }
@anilbathula@@anilbathula@

Thanks guys finally i found out solution with the help of my colleague Anoop.

 

 public PageReference redirectToPage() {
   
        String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
        Id id=selectedRecordType;
        
        String csRtId=RIIUtility.getRecordTypeId('Home Loan',new Lead());
        String carRtId=RIIUtility.getRecordTypeId('Car Loan',new Lead());               
        String crRtId=RIIUtility.getRecordTypeId('Credit Card',new Lead());
       
        
        if (selectedRecordType == csRtId){
            return Page.LeadTest.setRedirect(True);
            }
       
        if(id == carRtId) {
            PageReference p = new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType='+carRtId+'&ent=Lead ');
            p.getParameters().put('nooverride','1');
            return p;
         }  
       
        if(id == crRtId)  {
            PageReference p = new PageReference('/00Q/e?retURL=%2F00Q%2Fo&RecordType='+crRtId+'&ent=Lead ');
            p.getParameters().put('nooverride','1');
            return p;
         }      
     
                  
        else
            return null;
    }

This was selected as the best answer