3

Please note that this is about Lightning Experience (with actions overridden), not Classic. So, getParameters() doesn't work here. Here is the output if someone needs to see it's output.

{id=XXXXX, isdtp=p1, nonce=XXXXX, sfdc.override=1, sfdcIFrameHost=web, sfdcIFrameOrigin=https://cs31.lightning.force.com}

I'm using Visualforce page in Lightning experience. The page is used to override edit/view pages.

In that page, there is button to open edit page which is binded to following function.

public PageReference customEdit() {

    PageReference viewPage = new ApexPages.StandardController(customer).edit();
    viewPage.setRedirect(true); 

    return viewPage;
}

When that button is clicked. URL is getting changed to .../edit

But how can i determine whether the page is in edit or view mode in the apex controller ?

View page URL -

https://cs31.lightning.force.com/one/one.app#/sObject/XXXXX/view

Edit page URL -

https://cs31.lightning.force.com/one/one.app#/sObject/XXXXX/edit

  • @glls This is about Lightning Experience, getParameters() won't work here. – ChamingaD May 10 '17 at 0:40
  • yup, i removed my comment, i read visualforce page in the question and ignored the fact that you had written lightning =P – glls May 10 '17 at 0:48
  • 1
    Hmmm...When showing a VF page in Lightning I can get parameters just fine as long as they are present in the link. For example, I have a button that directs to a VF url with the id param and the controller uses getParameters to get the Id param and it works just fine in Lightning. Of course I believe we are using two different navigation methods so maybe thats it – Eric May 10 '17 at 0:52
  • maybe @ChamingaD didnt test =P, people forget to test nowadays or simply dont read How to Ask and forget to include a lot of useful information such as what they did, what didnt work, what they expected – glls May 10 '17 at 0:54
  • 1
    Possible duplicate of Passing URL parameters from VF page to custom controller – Himanshu May 10 '17 at 4:54
0

getParameters works in LEX as well as long as the parameter is passed correctly and is in the URL(may not be visible in the browser URL).

You can pass the parameter in the pageReference instance you have in your edit action.

public PageReference customEdit() {

    PageReference viewPage = new ApexPages.StandardController(customer).edit();
    viewPage.setRedirect(true); 
    viewPage.getParameters().put('pageMode', 'edit');
    return viewPage;
}

And then fetch the parameter value in the constructor of the controller of the edit page.

ApexPages.currentPage().getParameters().get('pageMode');
  • This is not working anymore after Spring 17. – ChamingaD May 10 '17 at 13:33

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.