Tuesday, October 24, 2017

Use images in Formula Fields

Description
Create a Formula Field to display images based on the value of another field in an Object.
For example, use a Formula Field to highlight the status of an Opportunity, Lead, Case Age, or the dollar amount in a Contract.
Resolution


Steps to create a Formula Field that displays an image in Salesforce Classic


1. Create a public folder to hold your image files.
1. Click the Documents tab.
2. Click Create New Folder.
3. Enter the folder name (for example, "Public Images").
4. Give users "Read-Only" access to the folder and make it accessible to all users.
 
2. Upload your image file to your Documents storage area.
1. Click the Documents tab.
2. Click New.
3. Enter the document name to be displayed on the browser.
4. From the "Folder" picklist, select the folder you created in step 1.
5. Click Browse to look for and select the file to upload.
6. Click Save.
 
3. Repeat step 2 to upload all your image files.
 
4. Create a new "Text" type Formula Field.
1. Go to Setup | Customize | <Object> -- Select the Object you are going to customize (Accounts, Case, Opportunity).
2. Click Fields.
3. Under "Custom Fields," click New.
4. Select Formula.
5. Click Next.
6. Enter your custom field name, then select Text from the "Type" picklist.
7. Click Next.
8. In the "Enter Formula" screen, click Advanced Formula.
 
5. Obtain the URL to the files you uploaded
1. Click the Documents tab.
2. From the "Folder" picklist, select the folder you created in step 1.
3. Click Go.
4. Click View next to the name of the file you want to use.
- A new browser window or browser tab opens.
5. In the browser's address bar, select and copy the URL.
 
6. Enter your image URL into your Formula Field using the "IMAGE" function.

1. In the text area, enter your formula using IMAGE to retrieve the image file you uploaded in step 2. 
2. Paste the image document URL into the 'image_url' portion of the IMAGE function.

Notes
  • Don't include the Salesforce domain ("https://www.salesforce.com") in your URL.
  • URLs must be enclosed in double-quotes, for example: "/servlet/servlet.FileDownload?file=01570000000Q6El"

7. Repeat step 5 and step 6 for until each of your image URLs have been added to the Formula Field.
 
8. Grant the appropriate Field-Level Security to your Formula Field.
 
9. Include the Formula Field in all the relevant Page Layouts.
 

Example Formula Fields

Example #1

This example displays a GIF image of a green square if the amount of an opportunity is greater than 100, a yellow square if it's under 51 and 99, and a red square if it's less or equal to 50.
IF( Amount > 100, IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6El", "Green"),
IF ( Amount > 50, IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6Ef", "Yellow"),
IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6Ep", "Red")))

IMPORTANT: Although percentage fields appear to have whole number values, they are decimals. For example, 50% in the opportunity probability field is entered as 0.5, not 50. So the formula for a percent field should look like this (using probability field as example):
IF ( Probability > 0.50, IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6Ef", "Yellow")
 

Example #2 

This example displays the JPG image of a flower regardless of the value in any field.
IMAGE("http://images.odeo.com/1/8/4/Zencast.jpg", "Flower", 300, 300)

No comments:

Post a Comment

Lightning Inter-Component Communication Patterns

Lightning Inter-Component Communication Patterns If you’re comfortable with how a Lightning Component works and want to build producti...