All posts

Basics of Salesforce & Apex

What is Salesforce?
Salesforce is a CRM(Customer Relationship Management) in which Sales Processes are automated. We can customize it according to the requirements. Salesforce has several clouds: Sales Cloud, Service Cloud, Data Cloud etc. We will be focusing Sales Cloud in this blog.

Sales Process:
Sales Processes include management of Leads, making the Account and Contacts from the qualified leads and finally creating opportunities from converted Leads. Leads are our business sources or in other words Leads are those persons/customers who may or may not be interested in our company's products and services. So the Sales Person try to contact those leads anyhow and select the interested Leads from all those. Then those selected leads are followed up further to have business with us. Those leads who agree with the same are created as Accounts and Contacts. Then finally Opportunities are generated from those contacts and accounts.

Sales Process should be clear before beginning with the development part. But don't worry we won't spending much time on this. Lets start with the programming part.

Programming in Salesforce for Beginners includes:
1. Triggers,
2. Test Classes
3. VF Pages
4. Controllers

As a beginner you are supposed to know about OOPS Concepts. Knowledge of Java may be a plus point for you. But Java is very wide, for SalesForce only OOPS is sufficient.

Before we go to the coding part, some concepts of SalesForce are also necessary:-

Relationships: There are two types of relationships in Salesforce:
  • Lookup Relationship - It is a one-many relationship. For e.g.: Contact object has a lookup to Account that means Account is the Parent of Contact. We can access the Accounts' fields from Contact object through this relationship. It is not required to enter this lookup field while creating a record. Upon deleting the parent record child records will not be deleted.
  • Master-Detail Relationship - Everything is same as lookup relationship. The difference is that it is a required field while creating a child record. In master-detail relationship, master is mandatory otherwise child record cannot exist. If parent record is deleted then all child records are deleted. Only 2 master-detail relationships can be made on an object.
  • Many-to-Many Relationship - In salesforce many-many relationship can be achieved using another object which we call Junction Object. For e.g.: We want to have many-many relationship between object A and object B. Then we will create an object C. Then create two lookups of Object A and Object B on the junction object i.e. Object C.
Collections: There are 3 types of collections which are widely used in programming:
  • List - List can contain duplicate values. E.g.:
    List of string type can be declared as: List<String> listName;
    List can also contain Primitive datatype such as List<sObject> : List<Account> accList;
    Nested Lists can also be declared (means list of a list): List<List<Account>> mainList - This signifies that mainList is a list of (List of Accounts).
  • Set - Set doesn't contain duplicate values. It can only contain unique values. E.g.:
    Set<id> sid - This is a set of IDs.
  • Map - Map contains (Key,Value) pair. For each Key there is a value in map. There are two methods get and put to access the values from key and to put the values to a key respectively. For e.g.:

    Map<String,Integer> mapName = new Map<String,Integer>()
    ; // This map contains String type of key and Integer type of values.

    mapName.put('A',1);
    // Now we are putting values in the map like for key 'A' value '1' is assigned.
    mapName.put('B',2);
    mapName.put('C',3);


    Integer i = mapName.get('A'); // This statement is used to get the value of key 'A'. The result will be i = 1. Similarly we can get values from other keys: mapName.get('B');

    Map is very useful in programming. We can make very complex maps and can be used to write bulkified triggers.
    Map<id,List<sObject>> : This is a map of ID and a list of an object. For e.g.: We have several contacts under an Account. So for a single AccountID we can have multiple Contacts or List<Contact>.

First published on Blogger in 2013. Some screenshots and APIs have changed since; the code is kept as written.

  • apex
  • basics
  • classes
  • coding
  • controllers
  • crm
  • sales process
  • Salesforce