+ 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

Navatar_DbSupNavatar_DbSup

Hi

 

Try the below code snippet as reference:

 

PageReference('/'+'00Q/e?retURL=%2F00Q%2Fo&RecordType=012O000000003ds&ent=Lead');

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

@anilbathula@@anilbathula@

Hi Ankit,

 

Thanks for ur reply.

 

Ankit its not redirecting to standard page its redirecting to visual force page Lead Test.

 

I Want it should be redirected to standard page.

 

Thanks

Anil.B

AmitSahuAmitSahu
Hi, As you said, you have override the new page it is going in a loop . you need to stop that happening . just search for nooverride =1 somewhere in this forum and you should get the answer.
@anilbathula@@anilbathula@

hi j020

 

i used the nooverride option also but it still showing the same visual force page but its not redirecting to standard page.

 

my code for ur reference:

 

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@

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
kondru xavier 4kondru xavier 4
how to restrict redirect the visualforce page