1

I have a scenario where I override the edit button of a custom object and display a visualforce page instead of the standard page. My problem is that I also use the same visualforce page embedded inline in the page layout of the record. Is there anyway to detect from the visualforce page or the apex controller if we are in the readonly mode?

  • Do you want to know if the rendered page is VF Page or Standard page? – Samir Mar 3 '17 at 9:53
3

I am not sure about any direct options, but you can check for the id and retURL parameters present in URL to determine the mode.

Controller

public class CheckState {
    public String vfMode {get; set;}
    private Map<String, String> urlparams = new Map<String, String>();
    public CheckState(ApexPages.StandardController std){
        urlparams = ApexPages.currentPage().getParameters();
        if (urlparams.get('id') == null){
            vfMode = 'New';
        } else if (urlparams.get('id') != null & urlparams.get('retURL') != null) {
            vfMode = 'Edit';
        } else if (urlparams.get('id') != null & urlparams.get('retURL') == null){
            vfMode = 'View';
        }
    }
}

VF Page

<apex:page standardController="Account" extensions="CheckState" >
    {!vfMode}
</apex:page>
  • @Kevan - This is way too much work to check if you are inline when you can simply check for the 'inline' parameter. Since the VF page will never be shown in the standard edit page the new or view is irrelevant. – Eric Mar 3 '17 at 15:11
  • 1
    @Eric - Infact I have overrided the New and Edit button to open the Visualforce page. It displays a form. But I want to use the very same page Inline on a record. That's why I was wondering how to verify its state. Saroj Bera answer fit my scenario perfectly. But I do always keep in mind your solution. :) – Kevan Mar 3 '17 at 18:13
  • @Kevan - Ahh, makes sense....My answer would only be useful in the standard page layout... – Eric Mar 3 '17 at 18:18
2

Here is the simplest way, use the existing URL parameter. When placed inline the URL parameter inline=1 is added to the URL

and example:

<apex:page standardController="Account" showHeader="false" sidebar="false">

{!$CurrentPage.parameters.inline == '1'}

</apex:page>

You can extrapolate to the controller if you need to

Boolean isInline = ApexPages.currentPage().getParameters().get('inline') == '1';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.