You need to sign in to do that
Don't have an account?
test class for respective class:need help
i need to write test class for the respective class...i did like it but no coverage has been attained.
public class moveopportunity
{
List<Opportunity> selectopp;
public string campaignid1;
public string conactid;
List<CampaignMember> cmember;
public moveopportunity()
{
selectopp=[Select o.Id, o.CampaignId, (Select OpportunityId, ContactId From OpportunityContactRoles) From Opportunity o where Opportunity.StageName =:'Closed Lost'];
cmember=new List<CampaignMember>();
}
public void move()
{
if(selectopp!=null)
{
for(Opportunity O:selectopp)
{
O.CampaignId = '70190000000MjHs';
cmember=[Select c.ContactId, c.CampaignId From CampaignMember c where CampaignId =:'70190000000MjHs'];
for(integer i=0;i<O.OpportunityContactRoles.size();i++)
{
cmember[0].ContactId= O.OpportunityContactRoles[i].ContactId ;
}
update O;
update cmember;
}
}
}
}
i wrote test class as:
@isTest
private class moveopportunity_test {
static testMethod void myUnitTest() {
Opportunity opp = new Opportunity();
/*8opp.Id='00690000008BBTp' ;**/
opp.CampaignId='70190000000MjHs';
opp.StageName ='Closed Lost' ;
/*opp.OpportunityContactRoles.ContactId ='0039000000FtGgY';*/
insert opp;
moveopportunity ci = new moveopportunity();
ci.move();
}
}
how to modify to increase coverage to 75%
no coverage 0%
Hi Ankit,
As read you code I think u are not following the best practices of Apex development.
Some of Point I found that.
O.CampaignId = '70190000000MjHs'; // You shoud not use ID as hard code .
In Your test class you are writing the code
opp.CampaignId='70190000000MjHs';
You will get CROSS_REFERENCE_ENTITY Error. system need record Id but you are passing the Id but it will consider as string not recordId.
Try to write your code dynamic and based on best practice.
Let me know if you need any other Help
~Thanks
Onkar Kumar