You need to sign in to do that
Don't have an account?
Rahul
Test class for Opportunity
Please help me with the test class of following code. Iam getting only 10% coverage
trigger Opp on Opportunity (before insert,before update) {
List<opportunity> objvrList =[select Id , stagename from opportunity where stagename='Pending' and id=:'0060k000004rrFb' ];
boolean flagetoUpdate = false ;
for(Opportunity op :trigger.new){
if(op.stagename == 'pending')
{
flagetoUpdate = true ;
}
}
if(flagetoUpdate){
for(opportunity o : objvrList) {
o.stagename ='Lost' ;
}
update objvrList ;
}
}
trigger Opp on Opportunity (before insert,before update) {
List<opportunity> objvrList =[select Id , stagename from opportunity where stagename='Pending' and id=:'0060k000004rrFb' ];
boolean flagetoUpdate = false ;
for(Opportunity op :trigger.new){
if(op.stagename == 'pending')
{
flagetoUpdate = true ;
}
}
if(flagetoUpdate){
for(opportunity o : objvrList) {
o.stagename ='Lost' ;
}
update objvrList ;
}
}
Please check following sample code :
please remove following line in your trigger you will get 100% code coverage.
Hardcoding ids is not best practice and test class will not find this id.(and id=:'0060k000004rrFb')
To see organization data we need to use seealldata =True in the test class.
Hope this helps you.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
trigger Opp on Opportunity (before insert,before update) {
List<opportunity> objvrList =[select Id , stagename from opportunity where stagename='Pending' and createddate < LAST_90_DAYS ];
boolean flagetoUpdate = false ;
for(Opportunity op :trigger.new){
if(op.stagename == 'pending')
{
flagetoUpdate = true ;
}
}
if(flagetoUpdate){
for(opportunity o : objvrList) {
o.stagename ='Loss' ;
}
update objvrList ;
}
}