Standard Page vs your Visualforce Page | Techila
2076
single,single-post,postid-2076,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

Standard Page vs your Visualforce Page

STANDARD PAGE VS YOUR VISUALFORCE PAGE

Standard Page vs your Visualforce Page

I just found this stuff to be very exciting and thought would be worth sharing.

I was reading through the forums and found a particular post.. the description is like this..

The “New” button has to be overridden with a Visualforce Page. When the Visualforce page loads some calculations are performed and the user is either redirected to the standard new/edit page or he stays in the same Visualforce page… And the interesting part was the standard new/edit page has to be prefilled with data passed from the visualforce page…

This is how it can be done.. We will take Account as an example.. We will override the Account new button with a visualforce page..

I will create a Visualforce page.. Just a small one.

<apex:page standardController=”Account” extensions=”newvsold” action=”{!pageredir}”>

</apex:page>

And the Apex class would be.

public class newvsold

{

public newvsold(ApexPages.StandardController controller)

{

}

public Pagereference pageredir()

{

    Pagereference newpage = new Pagereference (‘/001/e?retURL=/001/’);

    return newpage;

}

}

So go ahead and override your “new” button with the Visualforce page you just created.. Now when you click on “New” button under Accounts what do you observe..

Yes the same old Account new page is displayed.. It is because we call a method in the “action” attribute of the page tag..(If you are unclear about the “action” attribute then read this article here ).. this method redirects the user to the normal new page.. Now let’s analyze the URL we have specified in the Pagerefernce…

/001/e?retURL=/001/ — The number 001 indicates Account, e indicated edit and retURL specifies where to go after hitting any button on the page.. Like 001 for Account all objects have a number.. You can always check it in the URL bar..

I simply did a redirection.. you can add any complex logic there…

Now going to the interesting part.. How will I prepopulate my new page with values…. Here it is

Go to the Account “new” page.

prepopulate my new page with values

Right-click and select “View Source” or “View Page Source”…. and in the window that appears search for “Account Name”…

View Page Source

Now after the place where you see “Account Name” look for “<input” and note the “id”

Account Name

In our specific case the id is “acc2” which denotes Account Name….

In the url bar just type … https://yoursalesforceinstance.com/001/e?acc2=test&retURL=/001/

Or you can modify the Apex Code as below…

public class newvsold

{

   public newvsold(ApexPages.StandardController controller)

   {

   }

   public Pagereference pageredir()

   {

       Pagereference newpage = new Pagereference (‘/001/e?acc2=test&retURL=/001/’);

       return newpage;

   } 

}

“acc2” denotes Account Name.. similarly all fields have own id… and you can pass values for as many fields as you like unless you do not exceed the maximum URL size…

Even though this sounds a very strange method.. i just thought it might help someone somewhere..

Courtesy: http://www.forcetree.com/2009/07/standard-newedit-page-vs-your.html
https://www.minddigital.com/wp-content/uploads/2014/01/Visualforce-Page-In-Salesforce.jpg

“Explore – Techila Global Services, A Salesforce development company”

Author: techila

No Comments

Post A Comment