+ Start a Discussion
MarioCMarioC 

Auto-assign required fields

I have an issue I am hoping to get resovled soon.  On my page layouts for Opportunities, Opp Name and Close Date are required fields (as we all know).  I want to be able to automatically have the fields assigned a value wiothout user interaction.  I can create a workflow that does this, but then they still need to enter something in the fields in order for the workflow to run.  Can I use a trigger to assign the fields?  I would like the Opp Name to be the account name+date and time.  Then I would like the Close date to be today + 6 months.  I have the formulas already from the workflow, I just need to know if I should look to use a trigger- or something else.

 

Thanks, 

Best Answer chosen by Admin (Salesforce Developers) 
MarkSilberMarkSilber

To get it to open in the same window, you need to select "Display in existing window without sidebar or header" in the Behavior dropdown field.

You were close on the URL. Here's what I changed it to and it works fine in one of my orgs:


/006/e?RecordType=012600000009LOP&CF00N50000001M7fJ&CF00N60000001QfdF={!Contact.Name}&opp3={!Account.Name}&opp4={!Account.Name}&opp4_lkid={!Account.Id}&opp9={!TODAY()}&opp11=Open&retURL=%2F{!Account.Id}&cancelURL=%2F{!Account.Id}
 

First, you want to make sure you don't use the actual URL of the Salesforce pod (CS2, NA1, etc.). You can start with a forward slash instead of https://cs2 ... since you are already logged into Salesforce -- it knows what instance / pod you are on. This will make the custom button more portable between your sandbox and production environments.

You were using {!NOW()} -- which is a date/time field. You should use {!TODAY()} to just return the date since the Close Date field is a Date field, not Date/Time. If you need to default the Close Date to a future date, you might have to create a formula field on the Account object to add x # of days to Today's date and use that field in the URL instead of {!TODAY()}.

I added a new parameter, opp4_lkid={!Account.Id}. This sets a hidden field on the Opportunity to the actual ID of the Account and helps when you have more than 1 account with the same name. By setting this field, it will avoid a message on the screen about finding more than 1 matching account and forcing the user to select one. Since they are coming from the Account screen, we already know what Account the Opportunity is for.

I also changed the retURL to return to the Account you started from versus Opportunity tab and added a cancelURL to do the same thing. When they save the Opportunity, it will remain on the Opportunity screen (which is what I recommend).

I'm not sure where you are getting {!Contact.Name} from. If you are starting on the Account record and click your new button to create a new Opportunity, then it won't know what Contact to use. If you duplicate the button on a Contact record, you will have to make some minor modifications to bring in the Contact's Account. Since I don't have a Contact field on my Opportunity, this parameter was ignored in my testing.

 

Lastly, in your Opp11 field (stage), you need to make sure the values match. That is, you have to have a value in the picklist for "Open" for it to pre-populate the field.

 

I hope some of this makes sense. Give it a try and let me know if you are still having problems.

- Mark

All Answers

MarkSilberMarkSilber

One easy (no code method) is to override all buttons that create new Opportunities to pass specific values to the Opportunity screen, including the Account Name and Today's date. You may have to create a field on the Account to store Today's date in a formula field so you can pass it. For the Close Date, you would need to do a similar thing. Create a formula field on the Account that takes today's date and adds six months. Then pass that value in the URL that is used to create a new Opportunity. There are plenty of examples on the board for creating this type of custom button. The fields don't have to exist on any page layouts for this to work.

The solution above would only work if you are asking users to always create Opportunities from the Account page -- it would be easy to pass the data that way. If they start with a blank Opportunity and select the Account, it's pretty much impossible to do what you are asking without resorting to Visualforce.

 

You aren't actually overriding the buttons -- you are creating new buttons (i.e., "New Opportunity" ) on the Opportunity object and then adding them to the Opportunity related list on the Account screen and removing the default "New" button.

Message Edited by Mark Silber on 03-10-2009 06:50 PM
Message Edited by Mark Silber on 03-10-2009 06:50 PM
MarioCMarioC
Thanks Mark.  One of my issues is that I have two different offices (US and UK) that have seperate record types for everything (accounts, opps, contacts, etc).  So to override a button I will have to write some code that would differentiate between the profiles and open the appropriate record page layout...  I know there is something in the VF cookbook that allows you to assign pages to some users, but not all users.  Is that what I should look to do?
MarkSilberMarkSilber

It depends on how many different layouts you are talking about. If it's only a handful of Account / Opp layouts, then you can create buttons on the Opportunity object for every Record Type. You then just need to expose the appropriate button on the Opp related list on the matching Account page -- I hope that makes sense.


What you will end up with is multiple buttons that are all named the same thing, but call slightly different URLs. Again, this is manageable with a handful of combinations, but could get out of control if you have bunches.

MarioCMarioC
That would work fine for us, since the account and contact pages are only used by US users and they are the ones that need to create the Opps.  Now I need to scour for the code to create the button.  Is this in any of the manuals?
MarkSilberMarkSilber

Here's a good start. What you are looking for is information on creating custom buttons to pass information via the URL to fields on a screen. Custom Button Information Post.

 

Let me know if you need more assistance. To give you a head start, you will need to use Firefox to help build the buttons and should get the Firebug add-on to help figure out what the unique field names are in the page layout. This will make more sense when you read up on the topic.

 

Let me know if you need more help.

MarioCMarioC

It looks like I need a slight hand with this.  I creted a button on the Contacts tab that looks like this-

 

https://cs2.salesforce.com/006/e?retURL=%2F006%2Fo&RecordType=012600000009LOP&CF00N50000001M7fJ&CF00N60000001QfdF={!Contact.Name}&opp3={!Account.Name}&opp4={!Account.Name}&opp9={!NOW()}&opp11=Open

 

The issue I have is that-

1. It opens in a whole new window rather than the frame

2. nothing carries over.  It opens the new opp, but all the fields are blank.

 

I am sure this is a syntax (user) error.  Any help?

Thanks,

MarioCMarioC

sorry.. link does not appear...  here it is-

 

https://cs2.salesforce.com/006/e?retURL=%2F006%2Fo&RecordType=012600000009LOP&CF00N50000001M7fJ&CF00N60000001QfdF={!Contact.Name}&opp3={!Account.Name}&opp4={!Account.Name}&opp9={!NOW()}&opp11=Open

MarkSilberMarkSilber

To get it to open in the same window, you need to select "Display in existing window without sidebar or header" in the Behavior dropdown field.

You were close on the URL. Here's what I changed it to and it works fine in one of my orgs:


/006/e?RecordType=012600000009LOP&CF00N50000001M7fJ&CF00N60000001QfdF={!Contact.Name}&opp3={!Account.Name}&opp4={!Account.Name}&opp4_lkid={!Account.Id}&opp9={!TODAY()}&opp11=Open&retURL=%2F{!Account.Id}&cancelURL=%2F{!Account.Id}
 

First, you want to make sure you don't use the actual URL of the Salesforce pod (CS2, NA1, etc.). You can start with a forward slash instead of https://cs2 ... since you are already logged into Salesforce -- it knows what instance / pod you are on. This will make the custom button more portable between your sandbox and production environments.

You were using {!NOW()} -- which is a date/time field. You should use {!TODAY()} to just return the date since the Close Date field is a Date field, not Date/Time. If you need to default the Close Date to a future date, you might have to create a formula field on the Account object to add x # of days to Today's date and use that field in the URL instead of {!TODAY()}.

I added a new parameter, opp4_lkid={!Account.Id}. This sets a hidden field on the Opportunity to the actual ID of the Account and helps when you have more than 1 account with the same name. By setting this field, it will avoid a message on the screen about finding more than 1 matching account and forcing the user to select one. Since they are coming from the Account screen, we already know what Account the Opportunity is for.

I also changed the retURL to return to the Account you started from versus Opportunity tab and added a cancelURL to do the same thing. When they save the Opportunity, it will remain on the Opportunity screen (which is what I recommend).

I'm not sure where you are getting {!Contact.Name} from. If you are starting on the Account record and click your new button to create a new Opportunity, then it won't know what Contact to use. If you duplicate the button on a Contact record, you will have to make some minor modifications to bring in the Contact's Account. Since I don't have a Contact field on my Opportunity, this parameter was ignored in my testing.

 

Lastly, in your Opp11 field (stage), you need to make sure the values match. That is, you have to have a value in the picklist for "Open" for it to pre-populate the field.

 

I hope some of this makes sense. Give it a try and let me know if you are still having problems.

- Mark

This was selected as the best answer
MarioCMarioC

Mark- thanks a ton.  That was it.  It worked.  I appreciate your help and thanks again for "teaching me to fish" rather than "giving me a fish."  Learning this is going to be extremely beneficial for me.

 

Thanks again.