function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
srikanth11srikanth11 

help for test case

hi this is the trigger i have written

trigger Auto_Populate_salesteam_create_splits on Opportunity (after insert) 
{
for(opportunity o:trigger.new)
{
//GET ALL ACCOUNT TEAM MEMBERS EXCEPT THE OWNER OF THE OPPORUNITY
integer comm =0;
opportunityteammember[] otm = [select id,UserId from opportunityteammember where opportunityid=:o.id];
Integer otmcount = otm.size();
system.debug('otmcount:'+otmcount);
splits__c spl4oppowner = new splits__c();
spl4oppowner.opportunity__c = o.id; 
spl4oppowner.user__c = o.ownerid; 
spl4oppowner.Split__c = (100/(otmcount+1));
insert spl4oppowner;

for(opportunityteammember otm1:otm){

comm =  (otmcount);
splits__c spl = new splits__c();

spl.opportunity__c = o.id;
spl.user__c = otm1.userid;
spl.Split__c = (100/(comm+1));
insert spl;
//comm= comm+1;

}
}

}
this is the test case i have written AND I AM GETTING 64 PERCENT PLZ HELP ME GET 100%
@istest
private class Auto_Populate_salesteam_create_splits_TC
{
static testmethod void validateabc()
{
account a =new account();
a.name='sdsd';
insert a;


user u =[select id from user where isactive=true limit 1];



opportunity o= new opportunity();
o.name='sadsd';
o.StageName='100% - Order In House';
o.CloseDate=date.ValueOf('2011-09-21');
o.Accountid=a.id;
o.Unit_Size__c='PG 4C';
o.Ad_Type__c='Classified';
o.Campaign_End_Date__c=date.ValueOf('2011-12-07');
o.Campaign_Start_Date__c=date.ValueOf('2011-12-07');
o.recordtypeid='012A0000000ufHv';
insert o;
accountteammember a1=new accountteammember();
a1.userid=u.id;
a1.accountid=o.AccountId;
insert a1;

opportunityteammember otm=new opportunityteammember();
otm.userid=u.id;
otm.opportunityid=o.id;
insert otm;


}
}

 

 

Navatar_DbSupNavatar_DbSup

Hi,

 

Try this code but my suggestion is don’t use any SOQL query inside the test method because it will create error while deploying into production org. So create a record type instead of passing hard coded. I am considering the same code which you have mentioned. You this:

@istest
private class Auto_Populate_salesteam_create_splits_TC
{
	static testmethod void validateabc()
	{
		account a =new account();
		a.name='sdsd';
		insert a;
		user u =[select id from user where isactive=true limit 1];
		opportunity o= new opportunity();
		o.name='sadsd';
		o.StageName='100% - Order In House';
		o.CloseDate=date.ValueOf('2011-09-21');
		o.Accountid=a.id;
		o.Unit_Size__c='PG 4C';
		o.Ad_Type__c='Classified';
		o.Campaign_End_Date__c=date.ValueOf('2011-12-07');
		o.Campaign_Start_Date__c=date.ValueOf('2011-12-07');
		o.recordtypeid='012A0000000ufHv';
		insert o;
		accountteammember a1=new accountteammember();
		a1.userid=u.id;
		a1.accountid=o.AccountId;
		insert a1;
		opportunityteammember otm=new opportunityteammember();
		otm.userid=u.id;
		otm.opportunityid=o.id;
		insert otm;
		opportunity o1= new opportunity();
		o1.name='sadsd123';
		o1.StageName='100% - Order In House12';
		o1.CloseDate=date.ValueOf('2011-09-21');
		o1.Accountid=a.id;
		o1.Unit_Size__c='PG 4C';
		o1.Ad_Type__c='Classified';
		o1.Campaign_End_Date__c=date.ValueOf('2011-12-07');
		o1.Campaign_Start_Date__c=date.ValueOf('2011-12-07');
		o1.recordtypeid='012A0000000ufHv';
		insert o1;
	}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.