Activity Forums Salesforce® Discussions How to return reference to home page of object in Salesforce when clicked on a button?

  • How to return reference to home page of object in Salesforce when clicked on a button?

    Posted by Sharmila Sahoo on March 18, 2019 at 12:06 pm

    I need to override cancel button in VF page in Salesforce. I tried using return null in

    public pageReference cancelButton() {
    return null;
    }

    But it is not going anywhere after clicking on Cancel button.

    I tried to use:

    PageReference oppPage = new ApexPages.StandardController(opp).view();
    oppPage .setRedirect(true);
    return oppPage ;

    Still, it is not working.

    Does anybody have an idea how to navigate to Opp Home page if we click on cancel button in VF Page?

    Vinay replied 5 years ago 2 Members · 3 Replies
  • 3 Replies
  • Vinay

    Member
    March 21, 2019 at 8:21 pm
    public List<Opportunity> myOpportunities {get; set;}
    
    public pageReference cancelButton()
    {
      myOpportunities = [Id, Name, ...any other fields you want... FROM Opportunity];
      return null;
    }

     

    Hi Sharmila,

    Try defining list of Opportunities using  SOQL. Something like above.

     

     

     

  • Sharmila Sahoo

    Member
    March 22, 2019 at 5:57 am

    Hi Vinay,

    I tried this but still same issue. It is not going anywhere after clicking on cancel button.Actually I have created one visualforce tab which is launching VF page having standard controller(Opportunity)and extension.

    I got a way through

    <input type="button" class="btn" value="Cancel" onclick="window.location = '{!URLFOR($Action.Opportunity.Tab, $ObjectType.Opportunity)}'" />

    in vf page to redirect it to Opp Home page.

    It is working fine for classic but in lightning also it is navigating to classic view of Opp Home. Is there any way to control it so that when in classic it will move to classic view and when in lightning it will move to Lightning view of Opp Home page.

     

  • Vinay

    Member
    March 22, 2019 at 12:32 pm

    Have you tried using lightningStylesheets="true" attribute in your VF page. If possible, please post your code for VF page and controller.

    Thank you,
    Vinay.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos