Thursday, January 17, 2013

Simple Example for Apex Class and Test Class


/*----------- Apex Class---------- */

public class arithmaticCalculationClass{

    Integer answer;
   
    public void add(Integer a, Integer b){
   
        answer = a+b;
    }
   
    public void subtract(Integer a, Integer b){
   
        answer = a-b;
    }
   
    public void multiply(Integer a, Integer b){
   
        answer = a*b;
}
   
    public void division(Integer a, Integer b){
   
        answer = a/b;
    }
   
}


/*-------------Test Class --------------*/

@isTest

public class arithmeticCalculationTestClass{  
   
    static testMethod void testMyClass(){
   
        Integer x=20;
        Integer y=30;          
        arithmaticCalculationClass ins = new arithmaticCalculationClass();
        ins.add(x,y);
        ins.subtract(x,y);
        ins.multiply(x,y);
        ins.division(x,y);    
    }
}

No comments:

Post a Comment

Salesforce - Generate dynamic inner query to fetch parent and related child records

Use Case: In many scenarios, we need to clone the records with related child records. Issue / Limitation: We may simply use the "cl...