Browsing "Older Posts"

  • How To Compare Old Values And New Values In Salesforce Triggers

    salesforcepoint Monday, 2 December 2019

    How To Compare Old Values And New Values In Salesforce Triggers (How to check whether record values are changed or not in Apex Trigger)


    We know that salesforce Before update and After Update triggers fired/invoked based on Update DML event occurs, irrespective of any field value updated on record. But update triggers should not get invoked every time when record is updated. These trigger's should fire when corresponding field values got changed on record.

    If we want to know whether respective field value changed or not, we need to use trigger.new and trigger.oldMap context variables. As we know that trigger.New contains list of records which will have updated field values and trigger.OldMap contains map of records which will have old values. Lets take basic example: If Phone field value on Account got changed, then update Description field like "Phone number got updated from old Phone Number to New Number. Here the logic should not trigger every time, only gets triggered when only phone field value got updated.



    Trigger Helper Class

     public class Account_Helper {  
      public static void checkPhoneValueUpdated(List<account> newList, Map<Id,Account> oldMap) {  
        for(Account accountRecord: newList){  
        if(accountRecord.phone != oldMap.get(accountRecord.Id).phone){  
          accountRecord.description = 'Phone number got updated from'+oldMap.get(accountRecord.Id).phone+' to '+accountRecord.phone;  
         }  
        }  
      }  
     }  
    
    Trigger:
     Trigger AccountTrigger on Account(Before update){  
       if(trigger.isBefore &amp;&amp; trigger.isUpdate){  
         Account_Helper.checkPhoneValueUpdated(trigger.new, trigger.oldMap);  
       }  
     }  
    

  • Record Types In Salesforce

    salesforcepoint Tuesday, 29 October 2019
    Record Types: By using Record Types we can show multiple page layouts to one user for one object. By using Record types we can control pick list values of object.

    You may have doubt, as we have standard layout we can remove,add and rearrange fields and sections why do we have multiple page layouts.

    As we know by using page layouts we can remove unnecessary fields and we can add required fields. But some times there could be a scenario where we need to show some fields on record layout and those fields are not needed for another type of records. For example if we take Intermediate student, on student object we need to store subject wise Marks information, but Student can do anyone from MPC, BIPC, CEC courses. Each course have different subjects.

    So here we need to create Three page layouts for storing MPC, BIPC, CEC students information. 

    First we need to create fields for storing subject wise marks. Create below fields with field type is Number

    Sanskrit, English, Maths, Physics, Chemistry, Biology, Civics, Economics, Commerce.

    Create following layouts,
    1. MPC Student Layout
    2. BIPC Student Layout
    3. CEC Student Layout

    MPC Student Layout

    SETUP --> OBJECT MANAGER --> Student --> New
    Save. Drag New Section into Layout, update Name as "Marks Information". And Drag Sanskrit, English, Maths, Physics, Chemistry fields to this section like below image and click save.

    Like this create BIPC Student Layout, CEC Student Layouts as well add respective fields to Marks information section.

    Now we are done with creation of Page Layouts. Now we need to create three record types for three layouts.

    Creation of MPC Student Record Type.
    SETUP --> OBJECT MANAGER -->Student--> Record Types
    Step 1. Enter the details: Enter Record Type Label as "MPC Student", Check Active buton and check Enable for Profile checkbox(see below image). 

    Step 2. Assign page layouts: Select radio button "Apply one layout to all profiles"and MPC Student in drop down(see below image). Save

    Like Above steps mentioned Create BIPC Student, CEC Stuent Record Types.

    Now we are done with creation of Page layouts, Record Types creation. Now if you try to create new student record it will ask which type of record we need to create(check below image)

    If We select MPC Student we will see below layout
    If We select CEC Student we will see below layout
    Like how we can show different page layouts for users based on Record type selection



  • Page Layouts In Salesforce

    salesforcepoint

    What is Page Layout: 

    Page layout is nothing but a view that user can see. By using page layouts we can control below things.
    1. Which fields needs to displayed. We can can remove fields if not required on layout.
    2. Order/arrangement of fields
    3. We can create new sections, and can move fields to the section. (ex Address information section)
    4. We can add or remove related lists.
    5. We can add/remove buttons.
    6. We can make field as required and Read only.

    How to customize page Layouts Example:

    SETUP-->OBJECT MANAGER-->Student-->Page Layouts-->Student Layout

    Step 1 : Create New sections with Names (Address Information & Fee Information)
    select section(see below image) and drag into layout.
    step 2: update Section Name as Address Information(see below image). Click ok.
    Step 3: Drag State and city fields to "Address Information" section. (See below image). Click Save.


    Now go to any of Student record or try to create new Student record, you can see Address information section which have State & City fields. Like this we can arrange fields and create new sections by using page layouts.

  • Picklist Field in Salesforce & Field Dependencies in Salesforce

    salesforcepoint Wednesday, 23 October 2019
    Picklist Field in Salesforce: Pick list field is Drop down list of values. Basically we use picklist whenever we have requirement that we need to create field with pre defined values, user should enter the value from the predefined list of values only. In that case we go with Picklist.

    How to Create Picklist field in Salesforce:

    Example: I need to create a fields those should store State information and City information of Student. In this case we can create Country and State fields with field type piclist. 

    Field Label: State
    Field Type : Picklist
    Picklist Values: Andhra Prasdesh, Telangana, Tamil Nadu, Karnataka, Kerala..

    Field Label: City
    Field Type : Picklist
    Picklist Values: Vijayawada, Vishaka Patnam, Eluru, Guntur, Jaggayyapeta, Khammam, Hyderabad, Warangal, Karimnagar, Chennai, Bengaluru, Kochhin.

    Steps to create Picklist Field(State)
    SETUP-->OBJECT MANAGER --> Student

    Step 1. Choose the field type: Picklist
    Step 2. Enter the details : Field Label should be "State", In Values select radio button "Enter the values, with each value separated by a new line". Enter country values like below Image.

    Step 3. Establish field-level security
    Step 4. Add to page layouts and Save. Now we are done with the creation of State picklist field.

    Steps to create Picklist Field(S)
    SETUP-->OBJECT MANAGER --> Student

    Step 1. Choose the field type: Picklist
    Step 2. Enter the details : Field Label should be "City", In Values select radio button "Enter the values, with each value separated by a new line". Enter country values like below Image.
    Step 3. Establish field-level security
    Step 4. Add to page layouts and Save. Now we are done with the creation of City picklist field.

    If we go and create or edit student record we can see State and City picklist fields.

    Field Dependency in Salesforce:

    By using field dependencies in salesforce we can control the picklist values of  one picklist from another picklist value selection. If Controller picklist value changed then dependent picklist values automatically changed for user selection.

    Example: Inn above example we created two picklist fields i.e State and City.  If we try to create Student record, irrespective of State section we are displaying all values on City picklist field. But if we create field dependency between State & City, based on State selection city picklist value's changed that means for example if we select Andhra Pradesh then corresponding city's(Vijayawada, Vishaka Patnam, Eluru, Guntur, Jaggayyapeta) only displayed on City field.

    Important Note: Picklist which is controlling other Picklist field values called Controlling field. The field that has its values filtered based on other picklist field called the "dependent field."

    How to create Field Field Dependency in Salesforce:
    SETUP --> OBJECT MANAGER --> Student---> Field Dependencies --> New
    1. Select State as Controlling Field and City as Dependent field.
    2. Edit Field Dependency: We can see one column for every State and all the city's avilable in every column. See below screen
    3. Select City's based on State. By using Ctrl+click. See blow image, like that select city values for every state.

    4. Click on "Include Values" button. And click Save.

    Now try to create new Student record, you can see magic. If you select Andhra Pradesh as State then you will see Vijayawada, Vishaka Patnam, Eluru, Guntuu, Jaggayyapeta in City field and if you select Telangana as City you can able to Khammam, Hyderabad, Warangal, Karimnagaer.
  • Rollup Summary Field In Salesforce

    salesforcepoint Sunday, 20 October 2019

    What is Rollup Summary Field In Salesforce: 

    If you want to know about Rollup Summary, first you need to learn master detail relationship.
    follow link : http://www.salesforcepoint.com/2019/10/relationships-in-salesforce-and.html

    Rollup Summary is one of field type in salesforce. Rollup summary field only available if Master Detail relationship exists between parent and Child objects .we can create Rollup summary filed on parent object(Master object) only.

    What we can do with Rollup Summary Field:

    1. COUNT: We can calculate the count of Child records which are associated parent record.
    2. SUM: we can summarize particular field value of Child object.
    3. MIN: we can find out minimum value of particular field value of child object.
    4. MAX: we can find out Maximum value of particular field value of child object.

    example:

    We created Student and Branch objects earlier and established Master Detail between Student and Branch.
    Here Student is child and Branch is parent or master.

    scenario:  I want to find out number of Students who are associated with corresponding Branch.

    Go To Branch Object
    Step 1. Choose the field type: Roll-Up Summary
    Step 2. Enter the details: Enter Field label as "Number Of Students"
    Step 3. Define the summary calculation: Select "Students" as Summarized Object & Select "Count" radio button as Roll-Up Type
    Step 4. Establish field-level security
    Step 5. Add to page layouts.  Click Save. Go to Any of Branch record and you can see Number Of Students value that is count of student records of that Branch record.

    scenario 2: I want to Know how much of fee amount collected from particular branch.
    Go to Branch object
    Step 1. Choose the field type: Roll-Up Summary
    Step 2. Enter the details: Enter Field label as "Total Fee"
    Step 3. Define the summary calculation: Select "Students" as Summarized Object & Select "MAX" radio button as Roll-Up Type & Fee as Field to Aggregate
    Step 4. Establish field-level security
    Step 5. Add to page layouts. Click Save. Go to Any of Branch record and you can see Total Fee value that is summarized value of Fee from student records of that Branch record.
  • Relationships In Salesforce And Difference Between Lookup & Master Detail Relationship in Salesforce

    salesforcepoint Saturday, 19 October 2019

    Relationships In Salesforce & Lookup vs Master Detail Relationship in Salesforce

    Relationship: It is a concept of linking/relate one object to another object. Relationship can be setup on both standard and custom objects. Relationship used to define how records in one object relate to another object records. 
    Example: Accounts can be having a one-to-many relationship with opportunities that means one Account may have one or more related opportunity records.

    Lookup Relationship In Salesforce: Lookup relationship is simple relationship to link One Object to another Object. In this relationship Parent record is not mandatory while creating/updating record, that means we can create child record without entering parent record value.

    Master Detail Relationship in Salesforce:  Master Detail Relationship tightly coupled relationship between one object to another object. Why we called tightly coupled relationship, we can't create child record without entering parent value.  

    Difference Between Lookup and Master-Detail Relationship in Salesforce:
    Look Up Relationship
    Master-Detail Relationship
    We can create 25 lookup relationships for both standard and custom objects
    We can create only 2 master- detail relationships for both standard and custom objects
    Look Up Relationship can create even if records already exists in child object
    master- detail relationships cant be created if records already exists in child object.
    If we delete parent record, then child records will not be deleted/
    If we delete parent record, then child records will be deleted automatically.
    It is a Optional field
    It is a Mandatory field
    The ownership and sharing of a child record are not determined by the parent reord
    The ownership and sharing of a child record are  determined by the master record


    Lookup and Master Detail Relationship examples:

    If we take College, we can have Student table,  Teacher table, Branch table. First we need to create Student, Branch, Teacher Objects in salesforce.

    Create Student Object with following fields:
    1. Name (no need to create, by default it will come).
    2. Fee (field type: Currency)
    3. Year (field type: Picklist, picklist values: First Year, Second Year, Third Year).
    Create Branch Object :
    Create Teacher Object with following fields
    1. Name (no need to create, by default it will come).
    2. Experience in Number Of Years (field Type: Number).

    Now we are done with creation of Student, Branch, Teacher objects creation. Now we are going to create following relationships between the objects.

    1.Lookup relationship between Student and Teacher
    2. Master Detail relationship between Student and Branch.

    1.Lookup relationship between Student and Teacher

    Setup--> Object Manager--> Student-->Fields & Relationships-->New
    Step 1: Select Field type as Lookup Relationship

    Step 2. Choose the related object Teacher

    Step 3. Enter the label and name for the lookup field: Enter Class Teacher as a Label

    Step 4. Establish field-level security for reference field : Give Visible access to "System Administrator" profile only.

    Step 5. Add reference field to Page Layouts
    Step 6. Add custom related lists.
    and then click save. Now we are done with creation of lookup relationship between Student and Teacher object.

    Try to create Student record, you can see Class Teacher field that is lookup to Teacher object. You can select Teacher record in that lookup.
    Note: Try to save the record without entering Class Teacher field. Record will get saved even without entering Class Teacher lookup value. That means Parent is not mandatory in Lookup relationship.

    Now try to create record Teacher record with Vamshi and create student with Name Venu and class Teacher value as Vamshi and save the record. After that delete the Vamshi record on Teacher object and check Venu record exist or not, it will be there. Because in lookup  relationship if we delete parent record, child record wont be deleted.
    2. Master Detail relationship between Student and Branch.

    Important Note: Make sure that no records should be created on Student object. Because If we have records on Child object we can't create Master Detail Relationship directly. Check below screen shot.


    Setup--> Object Manager--> Student-->Fields & Relationships-->New

    Step 1: Select Field type as Master-Detail Relationship

    Step 2. Choose the related object : Branch
    Step 3. Enter the label and name for the lookup field
    Step 4. Establish field-level security for reference field : no need to do anything. click next.
    Step 5. Add reference field to Page Layouts
    Step 6. Add custom related lists
    Click Save. Now we are done with creation of Master Detail relationship between Student and Branch object. 

    Try to create Student record without entering Branch field, record won't be saved until we enter the Branch value. Because in Master Detail Relationship, Parent is mandatory field.

    Try to create Branch  record With name CSE. Now try to create Student record with name Venu Gutta and select Branch Value as CSE and Save the record.
    Now delete the CSE record on Branch object and check Venu Gutta record on Student object, record wont be available. In Master detail relationship if we delete parent record child record get deleted automatically.