Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
error

We made a wrong turn. Try again.

Hello Everyone,

Based on userLogin i need to shift the page layout.

Here is what i am trying to develop When user login is xx Country i need to some them standard contact pagelayout.Else i need to some them custom pagelayout.

Below is code 

<apex:page standardController="Contact" extensions="ContactRedirect" action="{!redirect}">

</apex:page>

Class

public class ContactRedirect {

public contact contact{get;set;}

public list<User> userList {get;set;}

 String recordId;

PageReference customPage;

    public ContactRedirect(ApexPages.StandardController controller) {

     recordId = controller.getId();

     system.debug('recordId'+recordId);

     

    }

    

    public PageReference redirect() {

        Id selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');

        

      User UserValue = [select Id,User_Country_Location__c from User where id = :UserInfo.getUserId()];

        system.debug('UserValue!!'+UserValue);

  if (UserValue.User_Country_Location__c=='XX') 

      {

         customPage =  Page.XXX;

        customPage.setRedirect(true);

        customPage.getParameters().put('id', recordId);

        //return customPage;

      } else {

             customPage= /00Q/e?retURL=%2F00Q%2Fo&RecordType='+selectedRecordType+'&ent=Lead;

            getParameters().put('nooverride','1');

            

    }

        return customPage;

    }

}

When ever i click on new button it goes to the page

https://c.cs13.visual.force.com/apex/RedirectButton?retURL=%2F003%2Fo&RecordType=012500000009kEg&ent=Contact&save_new=1&sfdc.override=1

and immedistely it redircet to "https://cs13.salesforce.com/null"

Can you please help me what i am missing
1 answer
  1. Oct 14, 2015, 10:01 PM
    Try this it will help you

     

    <apex:page standardController="Contact" extensions="ContactRedirect">

    <script type="text/javascript">

    window.onload = function(){

    alert('Gaurav');

    document.getElementById("FormId").submit();

    }

    </script>

    <html>

    <body>

    <form action="{!customPage}" target="_top" id="FormId">

    </form>

    </body>

    </html>

    </apex:page>

     

    public class ContactRedirect {

    public contact contact{get;set;}

    public list<User> userList {get;set;}

    String recordId;

    public PageReference customPage{get;set;}

    public ContactRedirect(ApexPages.StandardController controller) {

    redirect();

    }

    public PageReference redirect() {

    recordId = controller.getId();

    system.debug('recordId'+recordId);

    Id selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');

    User UserValue = [select Id,User_Country_Location__c from User where id = :UserInfo.getUserId()];

    system.debug('UserValue!!'+UserValue);

    if (UserValue.User_Country_Location__c=='XX'){

    customPage = Page.XXX;

    customPage.setRedirect(true);

    customPage.getParameters().put('id', recordId);

    //return customPage;

    }else{

    customPage= /00Q/e?retURL=%2F00Q%2Fo&RecordType='+selectedRecordType+'&ent=Lead;

    getParameters().put('nooverride','1');

    }

    return customPage;

    }

    }

     
0/9000