Tag: Salesforce Coding

  • Introduction To Collections In Apex | Salesforce Developer Guide

    Introduction To Collections In Apex | Salesforce Developer Guide

    INTRODUCTION:

    Collection: In general means ‘Group of things’.

    Basically there are 4 types of collection which are as-

      • List
      • Set
      • Map
      • Array.

    But here we are discussing only about three types which are supported by Apex(List,Set and Map).

    dont miss out iconDon’t forget to check out: Salesforce Apex Trigger – Parent to Child Trigger Using List

    1. List

    It is a collection of similar elements.

          • Size of the List can grow or reduce based on the runtime requirement.
          • Elements in the list are referred using index.
          • Index value starts with “0”.
          • List maintains insertion order.
          • List will accept duplicate values.
          • Salesforce has predefined apex class called List.
          • This class has predefined methods to support the operations on the list.

    The following two declarations are equivalent.

    The Str variable is declared using the List syntax.

    List<String> Str= new List<String>();

    Alternatively, the Str variable can be declared as an array but assigned to a list rather than an array.

    String[] Str = new List<String>();

    The example shows you both ways of adding elements to a list.

    List<String> Str = new List<String> { 'red', 'green', 'blue' };
    List<String> Str = new List<String>();
    Str.add('orange');
    Str.add('purple');

    This is an example which shows how to iterate over array elements.

    String Str1 = Str .get(0);
    String Str2 = Str [0];
    // Iterate over a list to read elements.
    for(Integer i=0;i<Str.size();i++) {
        // Write value to the debug log
        System.debug(Str[i]);
    }

    There are various methods used in lists-

    add(),addAll(),clone(),clear(),get(),remove(),size(),isEmpty() etc.

    2. Set

    A set is an-unordered collection of objects that doesn’t contain any duplicate values.Use a set when you don’t need to keep track of the order of the elements in the collection,and when the elements are unique and don’t have to be sorted.

    OR

    • It is a collection of similar elements.
    • Size of the Set can grow or reduce based on the runtime requirement.
    • Elements in the set are referred using value NOT INDEX.
    • Index value starts with “0”.
    • Set maintain insertion order.
    • Set will NOT accept duplicate values.
    • Salesforce has predefined apex class called Set.
    • This class has predefined methods to support the operations on the Set.
    • Set cannot be displayed in PageBlocktable.
    • We can display set records by declaring a set reference name/variable. Eg. {!a}

    dont miss out iconCheck out another amazing blog by Anuj here: How to Use Salesforce Lightning Data Services

    The following example creates and initializes a new set,add some element,and checks if the set contains the string b’:

    Set<String> s = new Set<String>{'a','b','c'};
    if (s.contains('b')) {
        System.debug ('I contain b and have size ' + s.size());
    }

    Methods used in Set are the same as used in List.

    3. Map

    Maps are collections of key value pairs,where the keys are of primitive data types. Use a map when you want to store values that are to be referenced through a key.For example,using a map you can store a list of addresses that correspond to employeeIDs.

    OR

    • It is a collection of similar elements.
    • It is a key value pair.
    • The size of the map can grow or reduce dynamically based on run time requirement.
    • Key in the map should be unique.
    • Value in the map can be duplicated.
    Map<Integer,String> empAdd = new Map<Integer,String>(); 
    empAdd.put (1, '123 San Francisco, CA'); 
    empAdd.put (2, '456 Dark Drive, San Francisco, CA'); 
    System.debug('Address for employeeID 2: ' + empAdd.get(2));

    Maps also support a shortcut syntax for populating the collection when creating it.

    Map<String,String> myStrings = new Map<String,String>
    { 
        'a'=>'apple','b'=>'bee'
    }; 
    System.debug(myStrings.get('a'));

    References: WWW3, Programiz

  • How to get Salesforce coding experience?

    How to get Salesforce coding experience?

    Well, fitting into a Salesforce developer career need no prior exercise. However, it is recommended and, in fact, better to acquire certain experience so as to improve yourself and derive the best placement opportunities. Whether you are a fresher or a professional doesn’t matter — if you are willing to move to Salesforce profession, then better put your efforts to achieve the desired goal. We have provided you some important tips to get you closer towards Salesforce career.

    Ways to Experience Salesforce Coding:

    Salesforce coding is not that difficult if you are keenly interested to shape yourself as a Salesforce developer. Here are some simple ways to gain experience in Salesforce coding.

    Develop with Building own Salesforce Org:

    One of the best ways to learn Salesforce is to prefer building your own Salesforce Org. Select a spreadsheet and start a free developer org. Then, a spreadsheet is to be rebuilt in Salesforce. Practice the code stuff and swift in your way of Salesforce career. However, ensure that you follow proper instructions ever to deal with coding and managing Salesforce Applications.

    Deal with Developer Forum:

    Developer forum is an extraordinary option which provides various questions — they can help you know and improve your Salesforce development skills. Try to answer the questions in the developer forum — in the process, you can revise your Salesforce knowledge, and find new ways and develop yourself.

    Get Hands-On Experience by Salesforce Training:

    Salesforce Training is offered by many training institutes nowadays helping trainees a lot to develop Salesforce skills and assisting in setting their career with Salesforce. Simultaneous to the theoretical explanations, you can also attain better lab practice — mentors, trainers, and other staff help you in your daily practice sessions and assignments. This way, you can attain the best hands-on experience in Salesforce coding. Any queries and doubts while coding can be easily cleared by the trainers and so this can be more helpful to get personalized attention in improving your skills.

    Involve in Real-Time Project Works:

    The real-time project works from Salesforce training centers are the other best means for gaining Salesforce coding experience. Live case studies can help you expose to the Real-Time Salesforce Environment. You will have to think logically, develop accurate coding, and bring out specific insightful solutions for the project delivery. Obviously, your mentor staff will always be at your hand to help you out and boost your performance and help you improve in coding techniques.

    Focus on Salesforce Forums:

    Various Salesforce forums are available — they enable discussions, questions, conferences, etc. They help to share the ideas, answers, codes, and other trends in different modules of Salesforce. Trailblazer Community, Salesforce Stack Exchange, and many other Salesforce forums are there to help you out. Basic entry level, as well as advanced level questions, are provided on the forums — so you can try to answer them out and test yourself. You can take it as a challenge and find the right coding solutions.

    Take Initiative with NonProfit Organizations:

    Nonprofit organizations are those which do not strive for the profits — they try to seek out recognition of being available and develop into the best upcoming business. So, better get into such firms so that you will be more exposed to coding. You may not get more pay-scale, but experience matters a lot. You will be involved deeply into the issues, analyze the conditions, building codes, and provide successful services. Your individual coding capabilities can be upgraded and hence, you can develop a better path for your Salesforce Career.

    Check any Freelancing Work:

    Salesforce is not only helping working professionals — but it’s also been a good choice of an employer for women willing to work from home. Freelancing facilities are also found — you can check for such freelancing opportunities so that along with your training or current profession, you can improve your Salesforce coding skills. Within time, you will be shaping yourself as a professional Salesforce Developer.

    Now that you got some ideas, better concentrate to follow them and earn Salesforce Coding experience. Once you attain enough knowledge, apply for the certification examination. Upon experience and availing Salesforce developer certification, you can get excellent career options from reputed multinational companies anywhere in the world.