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
Jessica LJessica L 

How to redirect to a Page Layout instead of redirect to a VisualForce page from Apex code

Is there a way to redirect a user to an Account Page Layout based on logic in Apex code? There is a clear path to redirect to a VisualForce page, but I do not want to recreate the various Account Page Layouts in VisualForce.

 

I have read that you can include VisualForce elements in a Page layout, but I am either looking to redirect from the Apex code to a page layout or include a Page Layout in a VisualForce page (without recoding the PageLayout in VisualForce markup).

 

I realize that I can use profiles to direct a user to different Page Layouts, but I need more granular control than a profile will provide, hence the apex code.

 

Prajapati.LakhanPrajapati.Lakhan

Hi,

 

If you are not looking for specific page layout (independent of record type), here is a solution to leverage standard UI.

 

 

<!-- Use $Action global varialble to access the New action reference -->
<apex:outputLink value="{!URLFOR($Action.Account.New)}">New</apex:outputLink>
<br/>
<!-- View action requires the id parameter, a standard controller can be used to obtain the id -->
<apex:outputLink value="{!URLFOR($Action.Account.view, account.id)}">View</apex:outputLink>
<br/>
<!-- Edit action requires the id parameter, id is taken from standard controller in this example -->
<apex:outputLink value="{!URLFOR($Action.Account.Edit, account.id)}">Edit</apex:outputLink>
<br/>
<!-- Delete action requires the id parameter, also a confirm message is added to prevent deleting the record when clicked by mistake -->
<apex:outputLink value="{!URLFOR($Action.Account.delete, account.id)}" onclick="return window.confirm('Are you sure?');">Delete</apex:outputLink>
<br/>
<!-- From all custom buttons, links, s-controls and visualforce pages you can use the following to get the link of the object's homepage -->
<apex:outputLink value="{!URLFOR($Action.Account.Tab, $ObjectType.Account

 

 

 

 

 

 

 

 

Thanks,

Lakhan

Jessica LJessica L

If a user is an owner of an account record (that the user selected with a button or link), I want to redirect the user to the full view of the account (an account Layout Page with all data).

 

If the user is not the owner of the account record, I want to redirect the user to an Account Layout Page with very limited data about the account.

 

In my code, I am using UserInfo.getUserId to get the currently logged in user's ID and am comparing that to the ownerId of the account.

 

Can you help me determine if I can use UserInfo.getUserId from JQuery or javascript so that I can do all the programming within the page (as you have done)?

 

If not, can I redirect to an Account Layout Page from Apex code?

DCBoyDCBoy

We had a simliar requirement to show a record in two different page layouts depending on which button the user clicks. Unfortunately I dont believe there is a way to do it in an easy way so we kept a standard page layout and created a custom visual force page. By default the standard page is displayed and the custom page is made available from a button.

 

Another option you can explore is define two record types, map two page layouts for the same profile. When it is the account owner who is viewing the record then update the account with the record type of the owner page layout. When it is a non-owner then update the account with the other record type. The disadvantage of this option is that you have to update the record type to show the correct page but on the other hand you have to build a whole new visual force page.

Jessica LJessica L

DCBoy,

     Thanks for weighing in. Since our business rules dictate that the user is either allowed or not allowed to view the full account record, using a button and having two different Views is not an option for our situation.

     I like the concept of 2 record types, if only the record type could be interpreted and used from code instead of from the database. The record-type solution does not allow the owner and a non-owner of an account to view the account at the same time since both would be attempting to update the record type simultaneously.

    I am disappointed in PeopleSoft's framework in that there is no straightfoward solution to what seems like a fairly common use case. We have decided to abandon the use of the views and simply build a page for each case.

         Thanks again,

               Jessica