You need to sign in to do that
Don't have an account?
Belen Ares Paredes 13
Help with test code -
Hi!
I am an admin, not a developer and I am trying to overcome the fact that I cannot access the Name of a team member declaratively.
I found a trigger that does what I need but I am unable to write the test code for the deployment to pass. Can someone help, please??
So frustrating!
Thanks,
Belen
I am an admin, not a developer and I am trying to overcome the fact that I cannot access the Name of a team member declaratively.
I found a trigger that does what I need but I am unable to write the test code for the deployment to pass. Can someone help, please??
So frustrating!
Thanks,
Belen
trigger TRG_OpptyTeamMemberName on OpportunityTeamMember (before insert, before update) { Set<Id> setTeamMemberID = new Set<Id>(); for (OpportunityTeamMember otm: Trigger.new) { setTeamMemberID.add(otm.UserId); } Map<Id, User> usrMap = new Map<Id, User>([SELECT Id, Name, LastName FROM User WHERE Id IN :setTeamMemberId]); for (OpportunityTeamMember otm: Trigger.new) { User usr = usrMap.get(otm.UserId); otm.Team_Member_Name__c = usr.Name; } }
You can use test class like below:
Here, we are inserting OpportunityTeamMember by passing OpportunityId and UserId
This will cause trigger to start.
Then put an assert on Team_Member_Name__c to check if trigger is working .
It will give 100% code coverage.
Try the below code:
Don't hardcode any thing in the test class.
Thanks,
Maharajan.C