Activity Forums Salesforce® Discussions What is the difference between given two Salesforce Apex code in description?

  • PRANAV

    Member
    January 18, 2018 at 3:12 pm

    Hi Shariq,

    There are different ways you can refer to or instantiate a PageReference in one of the following ways:

    • Page.existingPageName
      Refers to a PageReference for a Visualforce page that has already been saved in your organization. By referring to a page in this way, the platform recognizes that this controller or controller extension is dependent on the existence of the specified page and will prevent the page from being deleted while the controller or extension exists.
    • PageReference pageRef = new PageReference('***partialURL***');
      Creates a PageReference to any page that is hosted on the Lightning platform. For example, setting 'partialURL' to '/apex/Hello' refers to the Visualforce page located at mySalesforceInstance/apex/Hello. Likewise, setting 'partialURL' to '/' + 'recordID' refers to the detail page for the specified record.
      NOTE: This syntax is less preferable for referencing other Visualforce pages than Page.existingPageName because the PageReference is constructed at runtime, rather than referenced at compile time. Runtime references are not available to the referential integrity system. Consequently, the platform doesn't recognize that this controller or controller extension is dependent on the existence of the specified page and won't issue an error message to prevent user deletion of the page.
    • PageReference pageRef = new PageReference('***fullURL***');
      Creates a PageReference for an external URL
    • You can also instantiate a PageReference object for the current page with the currentPage ApexPages method. For example: PageReference pageRef = ApexPages.currentPage();

    Hope this helps you.

  • Parul

    Member
    September 15, 2018 at 2:40 pm

    Apex code1-

    Creates a PageReference to any page that is hosted on the Lightning platform. For example, setting ‘partialURL’ to ‘/apex/Hello’ refers to the Visualforce page located at mySalesforceInstance/apex/Hello. Likewise, setting ‘partialURL’ to ‘/’ + ‘recordID’ refers to the detail page for the specified record.

    Apex code2-

    By referring to a page in this way, the platform recognizes that this controller or controller extension is dependent on the existence of the specified page and will prevent the page from being deleted while the controller or extension exists.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos