-3

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)+'%';

        }
    }
}
8
  • 1
    Please, ensure that you set all variables, related to score and count calculation to zeroes (blank values) for every record to be processed
    – kurunve
    Apr 14, 2017 at 10:52
  • I am bit confused because when i update record manually it's working like as expected.But in large set of records not working fine
    – Pavan tej
    Apr 14, 2017 at 10:54
  • What is happening when you are trying with large data set? Any error messages? Apr 14, 2017 at 10:56
  • 3
    hmm looks like you need to initialize Integer Score=0,Count=0,Total; inside for loop
    – Ratan Paul
    Apr 14, 2017 at 10:56
  • No it's calculating inappropaitely @SantanuHalder
    – Pavan tej
    Apr 14, 2017 at 10:56

1 Answer 1

1

yes for each record you need a different calculation thats why initialize Integer Score=0,Count=0,Total; inside for loop

Hope this will fix your issue

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .