You need to sign in to do that
Don't have an account?
PS81
help to write test case - new starter
Hi
I'm pretty much new to salesforce. As my first task i had written a trigger but need help to write a test case or test class. Please any help on this?
I'm pretty much new to salesforce. As my first task i had written a trigger but need help to write a test case or test class. Please any help on this?
trigger OpportunityWeightageRev on Opportunity (before update) { double prob_diff = 0; double Nrev = 0; //New revenue double Orev = 0; //Old revenue Opportunity OprLast; //Previous opportunity data for(Opportunity Opr : Trigger.new){ OprLast = Trigger.oldMap.get(Opr.id); if(OprLast.Probability != opr.Probability){ if(prob_diff==0){ prob_diff = math.abs(OprLast.Probability - opr.Probability); } if((opr.Total_Contract_Value__c==0) || (opr.Total_Contract_Value__c==null)) opr.Total_Contract_Value__c = 0; nrev = opr.Total_Contract_Value__c * (prob_diff/100); orev = OprLast.Weighted_Revenue__c; if(orev<>0){ opr.mplan__c = nrev / orev; } } } }
Try with belwo code .You need to assign stage name as per your organisation.You need to update with one stage which probability is different then the insert stage probability .
Fo rsome test class concept you can check belwo links !!
http://manojjena20.blogspot.in/2015/06/tips-and-tricks-for-test-class.html
Let me know if it helps !!\
Thanks
Manoj
All Answers
Try with belwo code .You need to assign stage name as per your organisation.You need to update with one stage which probability is different then the insert stage probability .
Fo rsome test class concept you can check belwo links !!
http://manojjena20.blogspot.in/2015/06/tips-and-tricks-for-test-class.html
Let me know if it helps !!\
Thanks
Manoj
Please see if this test class works for your trigger. Correct wherever needed.
@isTest
private class OpportunityWeightageRevtest(){
private static testmethod unittest1(){
Account acc = new Account(name = 'TestAcc');
insert acc;
Opportunity opp = new Opportunity(name = 'TestOpp',AccountId = acc.Id,StageName = 'Prospecting',Closedate = Date.Today(),Weighted_Revenue__c = 100);
insert opp;
Opportunity op = [Select id,StageName from Opportunity WHERE Id = :opp.Id];
op.StageName = 'Negotiating';
Test.startTest();
update op;
Test.stopTest();
Opportunity o = [Select id,StageName,mplan__c from Opportunity WHERE Id = :op.Id];
System.assertNotEquals(Null,o.mplan__c);
}
}
Thanks
Kumar
anything i'm doing wrong? or am i'm looking into the correct place for code coverage (as in test tab of the apex console)?
only when i hit 'Run all' i get the code coverage as 26% but when i hit 'Run' and select the test class and method i do not see any code coverage...why is that so? and below the code coverage hit:
how can i make it atleast 75% ?