You need to sign in to do that
Don't have an account?
Ludivine
How to write an adderror method in a trigger?
Hi,
When users are changing the Account Owner, I have made a trigger to change the Owner of the realated Contract as well.
When some mandatory fields are empty in the related contract, users see a red message with the name of the field to fill but it is abit frightning.
I want to add a adderror() method in my trigger to show them the following message : 'Please complete all mandatory field on contract page'
Can you help me add this in my trigger?
Many thanks.
When users are changing the Account Owner, I have made a trigger to change the Owner of the realated Contract as well.
When some mandatory fields are empty in the related contract, users see a red message with the name of the field to fill but it is abit frightning.
I want to add a adderror() method in my trigger to show them the following message : 'Please complete all mandatory field on contract page'
Can you help me add this in my trigger?
Many thanks.
trigger TriggerUpdateContractOwnerFromAcount on Account (after Update) { for(Account Acc :Trigger.new){ List<Contract> C = [select id, ownerid from Contract where Account.id = :Acc.Id ]; for (Contract Ctrct : C) If(Ctrct.Ownerid != Acc.Ownerid){ { Ctrct.Ownerid= Acc.Ownerid; } update C; } } }
You can do that by adding a boolean (Checkbox) field to the object inorder to determine whether validation rule needs to be bypassed or not.
Set it to 'True' in your trigger.
And in the Validation rule include logic to check the value in the field. If it's 'True' do not perform the Validation.
Lakshmi.
All Answers
https://developer.salesforce.com/forums?id=906F00000008zcBIAQ
I have changed a bit my trigger but it doesn't change anything on the windows.
This error is displayed on the windows that is called to changethe name of Account Owner :
My trigger :
The error :
The exception that you are getting above is because you have used the field EndDate of the object Contract for the check if(Ctrct.EndDate == null), however you have not queried for the field EndDate in List<Contract> C = [select id, ownerid from Contract where Account.id = :Acc.Id ];
Once you include EndDate in the query - List<Contract> C = [select id, ownerid, EndDate from Contract where Account.id = :Acc.Id ]; it should be fine.
Hope this helps.
Lakshmi.
I was wondering finally if it was possible to ignore the validation rules on Contract page and Update the contact Owner?
It would be fantastic in fact and maybe easier to write?
You can do that by adding a boolean (Checkbox) field to the object inorder to determine whether validation rule needs to be bypassed or not.
Set it to 'True' in your trigger.
And in the Validation rule include logic to check the value in the field. If it's 'True' do not perform the Validation.
Lakshmi.