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

  • 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