You need to sign in to do that
Don't have an account?
David Corns 16
Looking for help with a simple trigger on the Contract object
We have a custom picklist field on the Contract object and we are looking for help with a trigger that during the new Contract creation process will upon selecting a Contract custom picklist field particular value autopopulate the standard Contract Term (months) number field with a particular value e.g. 12. All this prior to saving the record.
You have to fill all required fields data in the UI while creating the record(Required field are shows with red mark) then if there is any validation rules in Contract object it will check your data entered in the screen so please check the system validations(Required fields, Data Type for data you entered) and custom validations(Validation rules created by you : setup --> Contract --> Validation Rules) in Contract object.
In Salesforce we have order of execution while you save the records. So first the Validations will fire in the background there after only the Trigger will fire.
so in contract object there is Some Standard fields are always madatory : Account Name,Contract Start Date,Contract Term (months).
so you must have to fill the some dummy value in Contract Term fields while save but it will changed as per your trigger value. So i think there is no use of trigger here to prepoulate the value.But you can keep the some static value here by using trigger.
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
All Answers
Here is the sample code
Update populateContract with api name of your custom field and 'Perticular Value' with the picklist value which you are checking in criteria
Mark answer as solved if it does help you.
I updated as follows but received the error message below:
trigger Type_of_Contract__c on Contract (before insert) {
for(Contract cntr : trigger.new ) {
if(cntr.Type_of_Contract__c == 'NDA') {
cntr.ContractTerm = 12;
}
}
}
"Error: Compile Error: Invalid character in identifier: Type_of_Contract__c at line 1 column 9"
Any thoughts as to where I am tripping up?
Thanks again.
change the Trigger Name:
trigger TypeofContract on Contract (before insert) {
for(Contract cntr : trigger.new ) {
if(cntr.Type_of_Contract__c == 'NDA') {
cntr.ContractTerm = 12;
}
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
Since that field is the required field, initially you have to enter some values in it , after record save value will be updated with 12.
Reason of validation error is, system validation runs before trigger.
Thanks,
Rahul
You have to fill all required fields data in the UI while creating the record(Required field are shows with red mark) then if there is any validation rules in Contract object it will check your data entered in the screen so please check the system validations(Required fields, Data Type for data you entered) and custom validations(Validation rules created by you : setup --> Contract --> Validation Rules) in Contract object.
In Salesforce we have order of execution while you save the records. So first the Validations will fire in the background there after only the Trigger will fire.
so in contract object there is Some Standard fields are always madatory : Account Name,Contract Start Date,Contract Term (months).
so you must have to fill the some dummy value in Contract Term fields while save but it will changed as per your trigger value. So i think there is no use of trigger here to prepoulate the value.But you can keep the some static value here by using trigger.
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj