Show Image in formula field in Salesforce

This is going to be a short article where you will learn how to show an image in the formula field in Salesforce. In this article we will create a formula field to show the profile picture of a contact.

1. Upload Image in Static Resources

First you need to upload an image in static resources in order to reference it in the formula field. Follow below steps to upload an image.

  1. Go to Setup
  2. Search for Static Resources.
  3. Click on new.
  4. Upload your image here with a meaningful name. Copy the Name of the static resource as it will be required while creating the formula field.

As we are taking an example of showing a profile picture in a contact record. What you can do is upload the Image with Name as FirstNameLastName. As you can see in the above image I have named it ShubhamLashkan. Now while creating the formula field I will use the field names to find the name of a static resource which will make my solution more dynamic.

2. Create a Formula Field

    We are done with uploading images in static resources. Now lets create a formula field in contact object. 

    1. Go to the Object Manager.
    2. Choose Contact Object.
    3. Click on Fields & Relationships.
    4. Click on New.
    5. For Datatype choose formula and click on next.
    1. For Field label enter Profile Picture, Field name will auto populate.
    2. In the Formula return type choose text and click on next.
    1. Paste the formula below and click on next.
    IMAGE('/resource/'+FirstName+LastName, FirstName+' '+LastName ,70,70)

    Here, we are using the Image formula where the first parameter is the image URL, the second parameter is a text, which will appear if the image is not found for some reason, and the last 2 parameters are height and width. As i have said  earlier while uploading Image in static resource we will use field name to generate image URL.

    1.  Click on next and click on save.
    FREE Salesforce Training
    FREE Salesforce Training

    3. Formula in action

    Now let’s create a contact record with the same firstname and lastname which we used while uploading images as static resources.

    As you can see this worked. If the image was not present in the static resource then you will see alternate text which we have set as FirstName LastName. See below image for example.

    I hope now you are able to show images in the formula field. If you have any doubts then please let us know in the comment box below.

    Shubham Lashkan
    Shubham Lashkan
    Articles: 8

    Leave a Reply

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