You need to sign in to do that
Don't have an account?
kaushik Sabapathy
test class for inserting new opportunityLineItem record based on inserting
Hi,
Im a beginner in Saleforce. Need help in creating test class for opportunityLineItem(for inserting values in opportunityLineItem).
I had a scenario in which i have to calculate TAV based on different input. I have created a apex class for it and it is working fine.
I have used custom setting in getting the details
Renewal :Subscription;MRR;Credit;Monthly;Pre-Pay;No-change;Upgrade;Downgrade;Reprice;Product Change
second value:Hardware;Software;Appliance;SW/HW
third value:Support and Maintenance;S&M:Annual
Public Static void tavcal1()
{
if(isCalculated==false){
String result;
List<OpportunityLineItem> direct2=[SELECT Product_Type__c,Line_Transaction_Type__c,Monthly_Net_Price__c,TAV_Category__c,TAV__c,Term__c,Interval__c FROM OpportunityLineItem where Opportunity.Type='Renewal'];
Map < String, OpportunityLine__c> customSettingsMap =OpportunityLine__c.getAll();
String filterStages = customSettingsMap.get('Renewal').Product_Type__c;
String secondStages=customSettingsMap.get('second value').Product_Type__c;
String thirdStages=customSettingsMap.get('third value').Product_Type__c;
// CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
System.debug('Filtered Stages == ' + filterStages);
System.debug('Filtered Stages == ' +secondStages );
for(OpportunityLineItem opp:direct2)
{
try
{
if(Trigger.isUpdate||Trigger.isInsert)
{
OpportunityLineItem oldOpp = (OpportunityLineItem)Trigger.oldMap.get(opp.Id);
if(filterStages.contains(opp.Product_Type__c)&&filterStages.contains(opp.TAV_Category__c)&&filterStages.contains(opp.Interval__c)&&filterStages.contains(opp.Line_Transaction_Type__c)){
if(opp.Term__c<=12)
{
opp.TAV__C=(opp.Monthly_Net_Price__c-oldOpp.Monthly_Net_Price__c)*opp.Term__C;
if(opp.TAV__C<0)
opp.TAV__C=0;
}
else
{
if(opp.Term__c<=12)
{
opp.TAV__c=(opp.Monthly_Net_Price__c-oldOpp.Monthly_Net_Price__c)*12;
if(opp.TAV__C<0)
opp.TAV__C=0;
}
}
}
else if(secondStages.contains(opp.Product_Type__c)&&secondStages.contains(opp.TAV_Category__c)&&(opp.Interval__c==null))
{
opp.TAV__c=opp.Monthly_Net_Price__c;
}
else
{
if(thirdStages.contains(opp.Product_Type__c)&&thirdStages.contains(opp.TAV_Category__c)&&thirdStages.contains(opp.Interval__c)){
if(opp.Term__c>12)
opp.TAV__c=((opp.Monthly_Net_Price__c *36) / 0.48) * 0.2;
else
opp.TAV__c=opp.Monthly_Net_Price__c;
}
}
}
}
catch (System.NullPointerException e) {
}
isCalculated = true;
update opp;
}
}/* end of for loop*/
} /*end of if*/
I dont know how to insert opportunity line item as it was asking product id to be inserted
i have tried to create a Product id but was not successful
Please suggest to insert a new record on opportunityLineItem
Regards,
Kaushik
Im a beginner in Saleforce. Need help in creating test class for opportunityLineItem(for inserting values in opportunityLineItem).
I had a scenario in which i have to calculate TAV based on different input. I have created a apex class for it and it is working fine.
I have used custom setting in getting the details
Renewal :Subscription;MRR;Credit;Monthly;Pre-Pay;No-change;Upgrade;Downgrade;Reprice;Product Change
second value:Hardware;Software;Appliance;SW/HW
third value:Support and Maintenance;S&M:Annual
Public Static void tavcal1()
{
if(isCalculated==false){
String result;
List<OpportunityLineItem> direct2=[SELECT Product_Type__c,Line_Transaction_Type__c,Monthly_Net_Price__c,TAV_Category__c,TAV__c,Term__c,Interval__c FROM OpportunityLineItem where Opportunity.Type='Renewal'];
Map < String, OpportunityLine__c> customSettingsMap =OpportunityLine__c.getAll();
String filterStages = customSettingsMap.get('Renewal').Product_Type__c;
String secondStages=customSettingsMap.get('second value').Product_Type__c;
String thirdStages=customSettingsMap.get('third value').Product_Type__c;
// CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
System.debug('Filtered Stages == ' + filterStages);
System.debug('Filtered Stages == ' +secondStages );
for(OpportunityLineItem opp:direct2)
{
try
{
if(Trigger.isUpdate||Trigger.isInsert)
{
OpportunityLineItem oldOpp = (OpportunityLineItem)Trigger.oldMap.get(opp.Id);
if(filterStages.contains(opp.Product_Type__c)&&filterStages.contains(opp.TAV_Category__c)&&filterStages.contains(opp.Interval__c)&&filterStages.contains(opp.Line_Transaction_Type__c)){
if(opp.Term__c<=12)
{
opp.TAV__C=(opp.Monthly_Net_Price__c-oldOpp.Monthly_Net_Price__c)*opp.Term__C;
if(opp.TAV__C<0)
opp.TAV__C=0;
}
else
{
if(opp.Term__c<=12)
{
opp.TAV__c=(opp.Monthly_Net_Price__c-oldOpp.Monthly_Net_Price__c)*12;
if(opp.TAV__C<0)
opp.TAV__C=0;
}
}
}
else if(secondStages.contains(opp.Product_Type__c)&&secondStages.contains(opp.TAV_Category__c)&&(opp.Interval__c==null))
{
opp.TAV__c=opp.Monthly_Net_Price__c;
}
else
{
if(thirdStages.contains(opp.Product_Type__c)&&thirdStages.contains(opp.TAV_Category__c)&&thirdStages.contains(opp.Interval__c)){
if(opp.Term__c>12)
opp.TAV__c=((opp.Monthly_Net_Price__c *36) / 0.48) * 0.2;
else
opp.TAV__c=opp.Monthly_Net_Price__c;
}
}
}
}
catch (System.NullPointerException e) {
}
isCalculated = true;
update opp;
}
}/* end of for loop*/
} /*end of if*/
I dont know how to insert opportunity line item as it was asking product id to be inserted
i have tried to create a Product id but was not successful
Please suggest to insert a new record on opportunityLineItem
Regards,
Kaushik
"You can write a test class for OpportunityLineItem by this way."
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi