function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pamela LauwPamela Lauw 

Prefill Close Date on New Opportunity

I've created a VF page and controller to override the standard "new" button on the Opportunity Home Page.  The intention is to pre-fill the close date with a relative date value (Ex. Today's Date), but for some reason when I use the Opp9, it prefills with an exact value (Ex. puts in as text {!Today()}.  I am not great with code, and I've thankfully been able to trial and error a lot from the community. Help please!

My Controller is as follows:

public class RedirectNewOpptyController {
    public RedirectNewOpptyController(ApexPages.StandardController controller) {
    }
    
    public pagereference navigateToURL(){
        return new pageReference('/setup/ui/recordtypeselect.jsp?ent=Opportunity&opp9={!Today()}&nooverride=1&retURL=%2F006%2Fo&save_new_url=%2F006%2Fe%3FretURL%3D%252F');
    }
}
 
 
Marek Kosar_Marek Kosar_
Hi Pamela,
try this:
public pagereference navigateToURL(){
     String someDate = String.valueOf(Date.today());
        return new pageReference('/setup/ui/recordtypeselect.jsp?ent=Opportunity&opp9='+someDate+'&nooverride=1&retURL=%2F006%2Fo&save_new_url=%2F006%2Fe%3FretURL%3D%252F');
    }
but I'm nut sure, if date will be in correct format for this url hack...... but hope you understand what I wanted to do and you can finish it :)

Marek
 
Caleb SidelCaleb Sidel
You don't need a VF page, you can simply have a custom button of type URL. (Disclaimer - only works in Salesforce Classic UI).  There are a lot of posts on how to do button hacks so you can Google "Salesforce Button Hack". Here is a nicely formatted blog post http://www.salesforceben.com/salesforce-url-hacking-tutorial/
Pamela LauwPamela Lauw
Thank you both!
Unfortunately, I can't use a custom button because I am trying to place this on the Opportunity Home Page and redirect the standard "New" button.
I've updated by VF page and it works now!  Thanks!
Marek Kosar_Marek Kosar_
You're welcome.
Please do not forget to mark best answer and so set topic to SOLVED ;)