You need to sign in to do that
Don't have an account?

Set Opportunity CloseDate field with trigger
Hello,
I am trying to somehow default the 'CloseDate' field in the Opportunity as the users have absolutely no need for the field. Basically, I want to remove the requirement that the user must put something in this field.
I have tried everything I can think of using workflow rules, etc. and have even written a 'before' trigger to give the field a value so that the record will save. This does not appear to work, and we still get the 'Invalid Data' error since a required field is not being filled in.
Is this field somehow special in that I cannot even get to it with a before trigger? Is there ANY way to hardcode/default this field?
thanks.
I am trying to somehow default the 'CloseDate' field in the Opportunity as the users have absolutely no need for the field. Basically, I want to remove the requirement that the user must put something in this field.
I have tried everything I can think of using workflow rules, etc. and have even written a 'before' trigger to give the field a value so that the record will save. This does not appear to work, and we still get the 'Invalid Data' error since a required field is not being filled in.
Is this field somehow special in that I cannot even get to it with a before trigger? Is there ANY way to hardcode/default this field?
thanks.
You could create a Visualforce page for creating opportunities, override the new button/link on opportunity and with a little Apex code behind the page you can default the value.
<rant>
I do realize that there is a VisualForce answer to this. However, It seems like an awful lot of effort to simply put a value in a field, really. For my own technical curiosity, what is the reason for the validation rules/required fields being executed before the 'before' triggers? Isn't one of the goals of the 'before' triggers to allow pre-processing of a record before it is committed to the data store? (I admit some naievete here) The additionally frustrating part is that I have no other options: I cannot even change the field label (which could also be made to support the user's requests)
</rant>
To your VisualForce point - I do understand the solution that you metioned, but is there any way to shortcut the creation of the VF page by referencing some 'new opportunity page' template? That is, can I create a VF page against the Standard Opportunity controller and somehow have all the default 'new opportunity' fields and layout just appear, or does it have to be rebuilt from scratch?
Final question, is there any way to override the 'new' button to simply use the 'New Opportunity' URL with a passed in URL parameter for the CreateDate field??
thanks much for all the information
gireesh