function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Korea leeKorea lee 

Calculation method for Apex class characters

We plan to implementapplication with force.com. Current System was implememted by Visula Basic6.

Current system is about 700,000char (350KS,1Step=20char) .So, we worry the limit of class charters.

Can you teach me best practice of calculation method  for Apex class characters.

Sandeep001Sandeep001

Hello, 

 

A single apex class can be up to 100,000 characters in length. The best practice is to avoid writing very big classes and instead distribute your code in multiple classes. 

jujubajujuba

HI Lee,

 

Here are some best practice of writing code:

1) we should ensure that the number of for loops inside the code should be less.

2) Instead of using the List, it's better to go for a Map so that in case if your code got any nested for loops we cane reduce them.

3) If you are checking some condition's in a for loop for some set of records what you have queried in your list, try to add that as where clause so that we can reduce the iteration.

 

for ex: List<Account> a = [select id,name, status from account];

 

for(Account ac: a)

   if(status == Active)

 

if your code have such sort of scenario just use that contain what you were checking in for loop as the where clause

 

List<Account> a = [Select id, name, status from account where status = Active];

 

By doing so we can eliminate the loops.

 

4) Try to eliminate Debug statements in for loops.

5) Instead of printing whole list in debug, try to print the size in debug.

6) It's better to have less number of debugs in a big code's.

7) Try to keep the variable name as small as possible.

8) Try to use this syntax for for loop 

       for (Account a: acclist) v rather than using the traditional syntax : for (integer I=0; I<acclist.size(); i++)

9) It's better to eliminate the curly braces for loop even that will be counted as character.

     ex: for(account a: acclist)

            {

                 if()

            }

        

            instead you can write that as 

                       for(account a: acclist)

                          if()

 

            by doing this we can reduce 2 character for every iteration

 

10) If there is any possibility of splitting the code you can write in separate class. But it's better to take care of above mentioned 8 steps in all the scenario's.

 

 

Rayachoti RaghavendraRayachoti Raghavendra
<----------calculator for if condtion statments------------->

public class Calculatoroperator {
     public static string Docalculation( integer a,integer b,string func ){
        if(func=='+'){
            func =string.valueOf(a+b);
        }else if(func =='-'){
            func=string.valueOf(a-b);
        }
        else if(func=='*'){
            func = string.valueOf(a*b);
            
        }
        
        
        
        system.debug('result='+func);
        return func;
        
    }
}
--------------------------------------------->
for executive anonymous window (Cntrl+E)

string Cal= Calculatoroperator.Docalculation(1,2, '+');
system.debug('cal'+cal);