Reading list Switch to dark mode

    Apex Programming Basics

    Updated 22 June 2015

    Apex provides a complete set of features for building business applications – including data models and objects to manage data, a workflow engine for managing collaboration of that data between users, a user interface model to handle forms and other interactions, and a SOAP API for programmatic access and integration.

    Apex Code extends the powerful and proven success of the Force.com platform by introducing the ability to write code that runs on salesforce.com servers. The language enables a new class of applications and features to be developed and deployed entirely on demand. These applications make existing Force.com apps “smarter” by providing the ability to capture business logic and rules – such as data validation – and make entirely new kinds of apps possible on demand – such as complex inventory checking and order fulfillment.

    Please Check the Some Basic Example on Apex given Below.

    1. For Display the Simple Text and Integer

    Integer A = 123;
    String B = 'Salesforce';
    System.debug('Value is =' + A);
    System.debug('String is =' + B);
    
    Output
    
    Value is =123
    String is =Salesforce
    

    2. Check whether the no is even or not

    Searching for an experienced
    Salesforce Company ?
    Find out More
    Integer n= 3;
    Integer r;
    
    r = System.Math.mod(n, 2);
    
    if(r == 0)
    {
    System.debug('The no is Even');
    } else
    {
    System.debug('The no is odd');
    }
    
    Output
    
    The no is odd
    

    3.To find the Biggest 3 no.

    integer x=1, y=-66, z=44;
    
    if (x > y)
    {
    if(x > z)
    {
    System.debug(x+ ' x is the Big');
    } else
    {
    System.debug(z+ ' z is the big');
    }
    } else
    {
    if(y > z)
    {
    System.debug(y+ ' y is the big');
    } else
    {
    System.debug(z+ ' z is the big');
    }
    }
    
    Output
    
    44 z is the big
    

    4.While Loop Example

    Integer deptt = 1;
    
    while (Deptt < = 10)
    {
        System.debug('Salesforce');
        Deptt = Deptt + 1;
    }
    
    Output
    
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    Salesforce
    

    5.Example of For Loop

    for(Integer J=0; J<=5; J++)
    {
        System.debug('Webkul SalesForce Department');
    } 
    
    
    Output
    
    Webkul SalesForce Department
    Webkul SalesForce Department
    Webkul SalesForce Department
    Webkul SalesForce Department
    Webkul SalesForce Department
    Webkul SalesForce Department
    

    6. Example of array

    integer[] a = new integer[4];
    a[0] = 10;
    a[1] = 20;
    System.debug(a[0]);
    
    Output
    
    10
    

    7.Assing 10 elements and print Reverse order

    integer[] a = new integer[10];
    for(integer i=0; i<10; i++)
     a[i] = i * 10; 
     
    for(integer i=0; i<10; i++)
     System.debug(a[i]); 
    
    System.debug('Array Elements Reverse Order');
    
    for(integer i = a.size()-1; i>=0; i--)
     System.debug(a[i]);
    
    Output
    10
    20
    30
    40
    50
    60
    70
    80
    90
    Array Elements Reverse Order
    90
    80
    70
    60
    50
    40
    30
    20
    10
    
    
    

    8. String Array Example

    integer[] a = new integer[] {10, 20, 30};
        string [] s = new string[] {'salesforce', 'Visualforse', 'cloud computing'};
    
    for(integer i=0; i<a.size(); i++)
        System.debug( a[i] +'  ' + s[i] );
    
    Output
    
    10  salesforce
    20  Visualforse
    30  cloud computing
    

    9. To find biggest element in array

    integer [] a = new integer[] {100, -20, 30};
        for(integer i=0; i<a.size()-1; i++){          
          if( a[i] > a[i+1]){
            integer temp = a[i];
            a[i] = a[i+1];
            a[i+1] = temp;
        }
        }       
    System.debug('The biggest elememnt is - ' + a[a.size()-1]); 
    
    Output
    
    The biggest elememnt is - 100
    

    Supported Framework Version -

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home