Browsing "Older Posts"

Browsing Category "Latest Salesforce Interview Questions"
  • 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);  
       }  
     }  
    

  • Page Layouts In Salesforce

    salesforcepoint Tuesday, 29 October 2019

    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. 
  • Difference Between Group By & Order By Clause in SOQL Salesforce

    salesforcepoint Saturday, 1 April 2017
    ORDER BY CLAUSE: The ORDER BY clause is used to sort the query result by specific fields by ascending or descending order. By default it returns query result in  ascending order.  If we want Query result in Descending order then we need to write "Order by FieldName DESC ".

    example: if we want to get latest Ten records created on Account, then query will be like below

    select NAME from ACCOUNT where createddate=today order by createddate desc limit 10

    above soql returns First Ten account records which was created  today.
    o/p:


    GROUP BY Clause:  The SOQL GROUP BY clause can be used for collecting data across multiple records and group the results by one or more columns.

    Group By Clause examples: 
    for example  i want to find out maximum "Annual Revenue" from Account records whose rating is "HOT".

    Query: SELECT rating, maX(annualRevenue) from account where rating='hot' group by rating

    for suppose if we want to find out Industry wise Maximum "Annual revenue" from account record whose rating is hot. Then query will be like below

    SELECT rating,industry, Max(annualrevenue) from account where rating='hot' group by rating, industry

    I want to find out how many Banking Industry Account records having no phone number

    SELECT industry, count(phone) from account where industry='Banking' group by industry

  • What is Recursive Trigger in Salesforce? How can we Avoid Recursive Trigger in Salesfore with Example

    salesforcepoint Tuesday, 21 March 2017

    What is Recursive Trigger in Salesforce?

    Recursive Trigger is a trigger which is called and called itself when some DML operation occurs. Recursion basically occurs when we perform same dml in the apex trigger method (ex: If we perform update operation in update triggers).  Recursion occurs when the trigger code called itself in a infinite loop until system throws error “maximum trigger depth exceeded”.

    Salesforce Recursive Trigger Simple Example:

    Trigger t1 on Contact(after  insert){
      Insert new Contact(Lastname=’Venu’, Phone=12345);
    }


    In above trigger, when we  inserts  new contact record , then the trigger t1 called, as per trigger logic new contact record should be created  and that new record calls again this trigger as it is after insert trigger  and again new record inserted it will be goes on in a loop until system stops. Finally  we will get error “maximum trigger depth exceeded” Like Below.





    How To Avoid Recursive Trigger in Salesforce?

    To avoid Recursive Trigger problem we have to create a public class with static Boolean variable as below.

     class:
    public class AvoidRecursive {
       public static boolean firstRun = true;
    }


    Trigger: 
    trigger TestTrigger on Contact (after insert) {
        if(AvoidRecursive.firstRun)
        {
            AvoidRecursive.firstRun = false;
            insert new Contact(Lastname=’Venu’, Phone=12345);
        }  
    }

    Here first time we set Boolean variable as “TRUE” in class .  In trigger variable is equals to true then it goes to inside loop, performs logic and then variable sets as “FALSE” so next  time it will not run(if variable=false then it will not goes to loop & will not perform logic). So if   Code will try to run second time in same request then it will not run.

  • Difference Between Trigger.new & Trigger.old in All Trigger Events with Example

    salesforcepoint Monday, 20 March 2017

    Trigger.new stores list of new records which are going to be inserted and updated into particular object.  Trigger.old stores list of old records which are updated with new values, which are going to be deleted from database.

    Example: I have created one custom object student and it has Name & Teacher custom fields. and if I try to insert new record what will happen..

    Trigger: I have written trigger to check what would be there in Trigger.new & Trigger.old when trigger event occurs. First of all we have to enable Debug Logs in our Organization, so that only we can check.

    trigger exampl26 on Student__c (Before Insert, After Insert, Before Update, After Update, Before Delete, After Delete, after undelete) {
     If(trigger.isBefore)
       {
           if(trigger.isInsert)
            {
            system.debug('Before Insert Trigger.new is---------- :'+trigger.new);
            system.debug('Before Insert trigger.old is------------ :' +trigger.old);
            }
           if(trigger.isupdate)
            {
            system.debug('Before Update Trigger.new is---------- :'+trigger.new);
            system.debug('Before Update trigger.old is------------ :' +trigger.old);
            }
          if(trigger.isDelete)
            {
            system.debug('Before Delete Trigger.new is---------- :'+trigger.new);
            system.debug('Before Delete trigger.old is------------ :' +trigger.old);
            }
       }
    If(trigger.isafter)
       {
           if(trigger.isInsert)
            {
            system.debug('after Insert Trigger.new is---------- :'+trigger.new);
            system.debug('after Insert trigger.old is------------ :' +trigger.old);
            }
           if(trigger.isupdate)
            {
            system.debug('after Update Trigger.new is---------- :'+trigger.new);
            system.debug('after Update trigger.old is------------ :' +trigger.old);
            }
          if(trigger.isDelete)
            {
            system.debug('after Delete Trigger.new is---------- :'+trigger.new);
            system.debug('after Delete trigger.old is------------ :' +trigger.old);
            }

            if(trigger.isundelete)
            {
            system.debug('after Undeletete Trigger.new is---------- :'+trigger.new);
            system.debug('after Undelete trigger.old is------------ :' +trigger.old);
            }
        }
    }

    Before Insert:

    Trigger.New:  (Student__c:{Id=null, Name=venu, Teacher__c=a0328000000nFUFAA2})
    Trigger.Old: NULL

    After Insert: After record inserted to Database

    Trigger.new: (Student__c:{Id=a0128000017bQrcAAE, Name=venu, Teacher__c=a0328000000nFUFAA2})
    Trigger.old:  NULL

    Before Update: i was trying to updated Student Name Venu to 'Venu Gutta' then

    Trigger.new: (Student__c:{Id=a0128000017bQrcAAE, Name=venu Gutta, Teacher__c=a0328000000nFUFAA2})
    Trigger.old: (Student__c:{Id=a0128000017bQrcAAE, Name=venu, Teacher__c=a0328000000nFUFAA2})

    After Update: 
    Trigger.new: (Student__c:{Id=a0128000017bQrcAAE, Name=venu Gutta, Teacher__c=a0328000000nFUFAA2})
    Trigger.old: (Student__c:{Id=a0128000017bQrcAAE, Name=venu, Teacher__c=a0328000000nFUFAA2})

     if I delete the That Record
    Before Delete: 
    Trigger.new: Null
    Trigger.old:  (Student__c:{Id=a0128000017bQrcAAE, Name=venu Gutta, Teacher__c=a0328000000nFUFAA2})

    After Delete:
    Trigger.new: Null
    Trigger.old:  (Student__c:{Id=a0128000017bQrcAAE, Name=venu Gutta, Teacher__c=a0328000000nFUFAA2})

    if I undelete that record from Recylic bin then:
    After Undelete:
    Trigger.new: (Student__c:{Id=a0128000017bQrcAAE, Name=venu Gutta, Teacher__c=a0328000000nFUFAA2})
    Trigger.old: NULL

    Click Here for Basic example trigger for Difference Between 
    Trigger.New and Trigger.old

    Difference Between Before and After Triggers In Salesforce





  • cognizant-CTS salesforce Interview Questions for Experienced & Freshers

    salesforcepoint Monday, 27 February 2017
    cognizant-CTS salesforce Interview Questions
    1.Tell me about What is crm life-cycle?
    2.What is lead conversion process and how its helpful in CRM?.
    3.What is SDLC? which methodology you are using?
    4.What is profile and explain profile components in salesforce?
    5. permission sets and explain its uses?
    6.difference between salesforce profile and permission sets
    7.What is workflow rules and briefly explain it? Difference between evaluation criteria created, and every time it’s edited and created & and any time it’s edited to subsequently meet the criteria?
    8.approval process in salesforce and give me one use case?
    9.What is report type?
    10 .Which reports support dashboards
    11 .What are sharing settings in salesforce? 
    12. Difference between summary and matrix report in salesforce?
    13. process builder& need of process builder?
    14.What are escalation rules and briefly explain
    15 .What is soap web service and briefly expalin how you know about that(It depends if you put in resume)
    16. How you can rate yourself in salesforce?
    17. What type of settings you can give in permission sets
    18.What are the technologies available in cloud computing other than salesforce
    19.Why salesforce is more popular?
    20. Difference Between Lookup & Master Detail Relationship in salesforce?
    21.what is web to Lead functionality in salesforce?
    22.What is email to case & web to case in salesforce?
  • Accenture Salesforce Interview Questions

    salesforcepoint Saturday, 25 February 2017

    Accenture- Salesforce Interview Questions(Admin, Development, apex, Trigger, Visualforce Pages)



    1. write a trigger on Account, While inserting a text value as 'someName' ended with 'text' ex: 'renuText' On Account Object it should through an error. How you will achieve this...??
    2. How you will write the Validation rule for the above scenario while inserting the record and the Validation rule should not fire while updating form workflow it shows be accept.
    3. In one of the objects there are two fields called Field1 and Filed2 exist and we have 100,000 records, out of 70,000 record values are equal in field1 and field2. Now Display those 70,000 records on visualforce page.
    4. In an Account Object a field called ‘Sales Person‘ and it has a lookup relation with the user object.
    If a user is selected as a salesperson for a record, that user is able to see those records, but OWD is private, the record owner and admin will not share any records.

    5. Soap & REST Differences and in which format these are used to send and receive.
    6. How you will get the Consumer Key and Consumer secrete.
    7. How to get the external ID from another system and update it in the Salesforce ExternalID field, if you get null value from other systems how you will through an error.
    8. How you will call other services
    9. Why do we use @future annotation?
    10. What is an asynchronous process and why it is needed?
    11. What is the purpose of using with sharing and without sharing?