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
And the Apex class would be..
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...
Right-click and select "View Source" or "View Page Source".... and in the window that appears search for "Account Name"...
Now after the place where you see "Account Name" look for "<input" and note the "id"
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...
"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..
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...
Right-click and select "View Source" or "View Page Source".... and in the window that appears search for "Account Name"...
Now after the place where you see "Account Name" look for "<input" and note the "id"
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..