You need to sign in to do that
Don't have an account?
Waqas Ali
Test class for contact roles
I am copying my contacts roles of old opportunity to new opportunit and also copying contact roles of opportunity to contact roles of newly created contract. Now how to wite test class for this ?
Guys any help ?
String theId = ApexPages.currentPage().getParameters().get('id'); List<OpportunityContactRole> oppRoles; oppRoles = [SELECT Id, OpportunityID, ContactID, IsPrimary, Role FROM OpportunityContactRole WHERE OpportunityId = :theId LIMIT 10000]; //copying contact roles of old opportunity to new opportunity if ( ! oppRoles.isEmpty()){ List<ContractContactRole> conRoles = new List<ContractContactRole>(); for (OpportunityContactRole oppRole : oppRoles) { conRoles.add(new ContractContactRole( ContactId = oppRole.ContactId, IsPrimary = oppRole.IsPrimary, Role = oppRole.Role, ContractId = myContract[0].Id)); } insert conRoles; } // myContract[0] is also defined and working fine, code will become long so here not mentioned, /// also copying the contact roles of opportunity to newly created contract if ( ! oppRoles.isEmpty()){ List<ContractContactRole> conRoles = new List<ContractContactRole>(); for (OpportunityContactRole oppRole : oppRoles) { conRoles.add(new ContractContactRole( ContactId = oppRole.ContactId, IsPrimary = oppRole.IsPrimary, Role = oppRole.Role, ContractId = myContract[0].Id)); } insert conRoles; }
Guys any help ?
For test coverage, create a test class to fire off this class/method.
For unit testing, run the scenario to see if you get the results you wanted to see.
thx.
All Answers
For test coverage, create a test class to fire off this class/method.
For unit testing, run the scenario to see if you get the results you wanted to see.
thx.
I re-read the original question and it is does not specify that you wrote your test class but unable to get it to 100% or that you are not sure how to write you test classes or you are asking whether your code even work at all and need to write test classes to verify your results.
If you need 100% coverage, can you post you test class so that we can analyze and let you know what's missing in it?
Thx.
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BQx3
Here is my test class, please read the question over there. I have done with Cotact role now get 100% code coveage how to write the unit test for wrapper class. Thank You.