You need to sign in to do that
Don't have an account?
Bob.390672021994282E12
test class adderror
Hello,
I am having an issue with my test class adderror on a trigger.
trigger Validation on ObjectA (before update) {
for(ObjectA lstVAdd : trigger.new){
if(lstVAdd.Supplier__c==null && lstVAdd.Status__c=='Closed' && lstVAdd.Comments__c ==null){
Trigger.new[0].Supplier.addError(My Message);
}
}
}
Thank you
I am having an issue with my test class adderror on a trigger.
trigger Validation on ObjectA (before update) {
for(ObjectA lstVAdd : trigger.new){
if(lstVAdd.Supplier__c==null && lstVAdd.Status__c=='Closed' && lstVAdd.Comments__c ==null){
Trigger.new[0].Supplier.addError(My Message);
}
}
}
Thank you
In your trigger, replace Trigger.new[0] with 1stVAdd as you are iterating over the ObjectA with the for loop using the 1stVAdd variable.
Try
if (....)
1stVAdd.Supplier.addError(MyMessage);
You also need to create a String variable MyMessage with a value.
Here are links to test methods for triggers:
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
Your trigger will only throw error on first record. because you are using Trigger.new[0].supplier. and also your supplier should be appened with '__C' since its a custom field. if you want to throw an error try adding 1stVAdd.Supplier__C.addError('MyMessage');
trigger Validation on ObjectA__C (before update) {
for(ObjectA__C lstVAdd : trigger.new){
if(lstVAdd.Supplier__c==null && lstVAdd.Status__c=='Closed' && lstVAdd.Comments__c ==null){
1stVAdd.Supplier__C.addError('My Message');
}
}
}