You need to sign in to do that
Don't have an account?
Zoom_V
Test code with Validation Rule issues
In my Validation Rule I am referring to an Opportunity field. The Opportunity is a grandparent to the record. My Validation Rule looks like this :
ISPICKVAL( Parent__r.Opportunity__r.Product__c,"")
The Validation Rule works fine. But it is still kicking off when I run my test code which is populating that field :
@isTest private class testProjectInitiationTrigger { static testMethod void ProjectInitiationTriggerTest() { Account account = TestHelper.createAccount(); Opportunity objOpp = TestHelper.createOpp(account); objOpp.Manager__c = objOpp.CreatedById; objOpp.Product__c = 'test'; update objOpp; //this is the parent record being created Project__c objC = TestHelper.createCBC(objOpp); objC.Supplier__c = 'Test Supplier'; update objC; //this is the child record which the trigger will run off Initiation__c oPI = new Initiation__c(); oPI.Name = objC.Name;
opI.Employee__c = opI.CreatedById; oPI.Parent__c = objC.Id; insert oPI; //this is the child record field which will initiate the post update trigger oPI.Initiate_Implementation__c = true; update oPI; } }
Why is the Validation Rule for the Opptunity Product__c field still kicking off when I run this test code ?
Thank you for any help.
Thank you - one more question : Should this line work :
objOpp.Manager__c = objOpp.CreatedById;
One of the validation rules is for the Manager__c field and I am still getting it. Should 'objOpp.CreatedById' work ?
If not, what can I use for that ?
Thank you very much
Can you please post the error message....
Thank you very much. I have now gotten the code to refer to the proper field in the Opp but I am still getting an error which is telling me I am using an incorrect form of data. This is the line :
For some reason it is not accepting objOpp.CreatedById in the code as a value. I am using that type of method later in the code for fields in the other objects involved such as this :
And that works. But for some reason it is not accepting objOpp.Manager__c = CreatedById in this code.
Does anybody know how to populate that field to satisfy the validation rule ?
Thank you very much for your help.
objOpp.Manager__c = objOpp.CreatedById;
Manager__c : Seems like you have a manager object in salesforce .Check the field, is this field parent is user?
You error message says ,its parent is different than user....
For this you have to do:
Manager__c mang=new Manager__();
//Set all the required field
mang.name='test';
insert mang;
objOpp.Manager__c=mang.id;