I need to calculate percentage based on multiple fields and i need to display field with percentage symbol.
So, I wrote a trigger and calculates the score and after converting in to text and concatenate % symbol to the field.
Trigger is working as expected with few records.But if try to write a test class to create like 100 records it is not working as expected
Let me know where i missed it.
public class Qualifier {
public static void QualificationScore(List<Lead> TriggerLeads)
{
Integer Score=0,Count=0,Total;
for(Lead Ls:TriggerLeads)
{
If(Ls.Number_of_Vehicles__c >= 5)
{
Score+=5;
Count+=1;
}
If(Ls.Unit_Potentialx__c >= 5)
{
Score+=5;
Count+=1;
}
boolean flag = (Ls.Vehicle_Type__c==null) ?true:false;
if(flag==false)
{
Score+=5;
Count+=1;
}
boolean Gpsused =(Ls.Current_Solution__c=='Yes') ?true:false;
if(Gpsused==true)
{
Score+=5;
Count+=1;
if(String.isNotEmpty(Ls.Solution_Name__c) && Ls.Solution_Name__c.toUpperCase() <>'NA' )
{
Score+=5;
Count+=1;
}
if(Ls.Solution_Price__c <> '0' && String.isNotEmpty(Ls.Solution_Price__c)
&& Ls.Solution_Price__c <> '0.0' && Ls.Solution_Price__c <> '0.00' && Ls.Solution_Price__c.toUpperCase() <> 'NA')
{
Score+=5;
Count+=1;
}
Boolean contracts = (Ls.Contract__c=='yes') ?true:false;
if(contracts==true)
{
Score+=10;
Count+=1;
if(Ls.Renewal_Date__c <> null)
{
Score+=10;
Count+=1;
}
}
Boolean contractsBlank = (Ls.Contract__c=='No') ?true:false;
if(contractsBlank==true)
{
Score+=20;
Count+=2;
}
}
Ls.Qualification_Score__c=String.valueOf(Score)+'%';
}
}
}
Integer Score=0,Count=0,Total;
inside for loop