You need to sign in to do that
Don't have an account?

Getting low code coverage
@isTest(seeAllData = true) public class OpportunityAddOnTest { public static TestMethod void MyTest() { List<Opportunity> OpportunityList = new List<Opportunity>(); Opportunity Opp1 = new Opportunity(); opp1.Name = 'opportnity_one'; opp1.CloseDate = date.today()-15; opp1.StageName= 'closed won'; insert opp1; Opportunity Opp = new Opportunity(); opp.Name = 'opportnity_one'; opp.CloseDate = date.today()-15; opp.StageName= 'closed won'; opp.Opportunity__c = opp1.id; insert opp; OpportunityList.add(opp); } }this is my test class
trigger OpportunityAddOn on Opportunity (after insert,after update) { if(!test1.IsOpptyUpdate) { test1.IsOpptyUpdate = true; List<Opportunity> updateList = new List<Opportunity>(); set<id> oppId=new set<id>(); for(Opportunity opp:trigger.new) { if(opp.Opportunity__c !=null) { oppId.add(opp.Opportunity__c); System.debug('parent id is-->' +opp.Opportunity__c); } } for(Opportunity partopp : [select id,Add_On_ARR__c,(select id,Opportunity_ARR__c from opportunities__r) from Opportunity where id in:oppId]){ Double countval = 0; if(partopp.opportunities__r.Size() > 0) { for(Opportunity child_op : partopp.opportunities__r) { if(child_op.Opportunity_ARR__c != NULL ) { countval = child_op.Opportunity_ARR__c + countval ; } } if(countval > 0) { partopp.Add_On_ARR__c =countval ; updateList.add(partopp); } } } if(!updateList.isEmpty()) { update updateList; } } }
this is my trigger..
Try with inserting records for opportunities__r.
Please refer below code.
Thanks,
Dhanya
Please let us know what error you are getting. Please share screen shot of error
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Jhall Bhugga: [Mobile__c] @ Amit
FIELD_CUSTOM_VALIDATION_EXCEPTION, Jhall Bhugga: [Mobile__c]
So itseems that there is some custom object related to Opportunity. So try inserting record for that custom object.
test1.IsOpptyUpdate
Please try below code
@isTest
public class OpportunityAddOnTest
{
public static TestMethod void MyTest()
{
Account acc = new Account();
acc.Name='Test Acc';
acc.phone = 1234567890;
insert acc;
List<Opportunity> OpportunityList = new List<Opportunity>();
Opportunity Opp1 = new Opportunity();
opp1.accountid =acc.id;
opp1.Opportunity_ARR__c = 1;
opp1.Name = 'opportnity_one';
opp1.CloseDate = date.today()-15;
opp1.StageName= 'closed won';
insert opp1;
Test.StartTest();
Opportunity Opp = new Opportunity();
opp.accountid =acc.id;
opp.Name = 'opportnity_one';
opp.CloseDate = date.today()-15;
opp.StageName= 'closed won';
opp.Opportunity__c = opp1.id;
insert opp;
test1.IsOpptyUpdate = false;
update opp;
Test.StopTest();
}
}
Please try to set Opportunity_ARR__c in both opportunity like below.
Try below code .
I hope 80% is good to go