Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Salesforce CRM Admin Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Salesforce CRM Admin Cookbook

Salesforce CRM Admin Cookbook - Second Edition

By : Paul Goodey
2.8 (5)
close
close
Salesforce CRM Admin Cookbook

Salesforce CRM Admin Cookbook

2.8 (5)
By: Paul Goodey

Overview of this book

Salesforce CRM is a market-leading customer relationship management (CRM) application that is accessed over the internet. This application greatly enhances a company's sales performance, improves customer satisfaction, and provides a robust customer relationship management system for an organization. Salesforce CRM Admin Cookbook, Second Edition enables you to instantly extend and unleash the power of Salesforce CRM and its Lightning Experience framework. It provides clear, comprehensive instructions along with detailed screenshots and code. Whether you are looking for solutions to enhance the core features, such as data management, process automation, data validation, and home page administration, or are looking for ideas on advanced customization techniques, this book will provide you with immediate, practical, and exciting real-world recipes. This book guides you through interesting topics spanning a variety of functional areas. Recipes are provided that allow you to configure, build and extend the capability of Salesforce CRM using the Lightning Experience framework.
Table of Contents (9 chapters)
close
close

Building an account credit score graphically with code

In this recipe, we will detail the steps to render an account credit score graphically using JavaScript and CSS within a Visualforce page.

We will add the Visualforce page as a component onto a Salesforce Account page using the Lightning App Builder and the image will appear on the main Account page as well as in the detail section of the page.

First, we create a custom Account Credit Score, which will feed the values rendered in the graphical range.

You can omit the steps in the following Getting ready section if you have previously carried out the steps in the Getting ready section of the Measuring account credit scores graphically using a Google image chart recipe.

Getting ready

Carry out the following steps to create a custom Credit Score field on the Account object:

  1. Click on the Setup gear icon in the top right-hand of the main Home page, as shown in the following screenshot:
  1. Click the Setup option, as shown in the following screenshot:
  1. Navigate to the Account customization setup page, by clicking the following: Objects and Fields | Object Manager | Account | Fields and Relationships.

Locate the Fields & Relationships section on the right of the page.

  1. Click New.

We will be presented with the Step 1. Choose the field type page.

  1. Choose Number from the Data Type options.
  2. Click Next.

We will be presented with the Step 2. Enter the details page.

  1. Enter Credit Score in the Field Label.
  2. Enter 3 in the Length field.
Accept the default option of 0 in the Decimal Places field, as shown in the following screenshot:
  1. Optionally, enter a value in the Description field.
  2. Optionally, enter a value in the Help Text field.
  3. Click Next.

We will be presented with the Step 3. Establish field-level security page.

  1. Select the profiles to which you want to grant edit access to this field via the field-level security. The field will be hidden from all profiles if you do not add it to field-level security.
  2. Click Next.

We will be presented with the Step 4. Add to page layouts page.

  1. Select the page layouts that should include this field. The field will be added as the last field in the first two-column section of these page layouts. The field will not appear on any pages if you do not select a layout.
  2. Finally, click Save.

How to do it...

Carry out the following steps to create a Visualforce page along with HTML and JavaScript code that will render an account credit score graphically:

  1. Click on the Setup gear icon, as shown in the following screenshot:

The Setup gear icon is located in the top right-hand area of the main Home page.

  1. Click the Developer Console option, as shown in the following screenshot:
  1. In the resulting Developer Console window, click on File.
  2. Click on New.
  3. Click on the Visualforce Page, as shown in the following screenshot:

We will be presented with a New Apex Page dialog.

  1. Enter CreditScore for the name of your new Apex Page.
  2. Click on OK, as shown in the following screenshot:
  1. Paste the following code:
<apex:page standardController="Account"> 
<style> 
  td.no_border{border:none} 
  td.green{background-color:#00FF00; border:none} 
  td.red{background-color:#FF0000; border:none} 
  td.grey{background-color:#DDDDDD; border:none} 
</style>  
<script>  
  window.addEventListener('DOMContentLoaded', function() { 
    var iLimit = {!Account.Credit_Score__c}; 
    var sHTML ; 
    var iThreshold = 40; 
    sHTML = '<table>'; 
    sHTML += '<tr>'; 
    sHTML += '<td class="no_border">0%</td>';    
    for(var i=0; i<100; i=i+5){ 
      if( iLimit <= iThreshold ){ 
        if( i<iLimit ) 
          sHTML += '<td class="red" nowrap="nowrap">&nbsp;</td>'; 
         else 
          sHTML += '<td class="grey" nowrap="nowrap">&nbsp;
</td>'; }else{ if( i<iLimit ) sHTML += '<td class="green" nowrap="nowrap">&nbsp;
</td>'; else sHTML += '<td class="grey" nowrap="nowrap">&nbsp;
</td>'; } } sHTML += '<td class="no_border">100%</td></tr></table>'; if( iLimit >= 0 ){ document.getElementById("CreditScore").innerHTML = sHTML +
"Credit Score : " + iLimit + "%"; } }); </script> <div id="CreditScore">Credit Score is not within limits</div> </apex:page>

  1. Click on File.
  2. Click on Save, as shown in the following screenshot:

Now set the profile security and Lightning accessibility settings for the Visualforce page by carrying out the following steps:

  1. Click on the Setup gear icon, as shown in the following screenshot:

The Setup gear icon is located in the top right-hand area of the main Home page.

  1. Click the Setup option, as shown in the following screenshot:
  1. Type the text visualforce in the Quick Find search box, as shown in the following screenshot:
  1. Click on Visualforce Pages.
  2. Click on Security for the CreditScore Visualforce Page.
  3. Click on Save.
  4. Click on Edit.
  5. Check the Available for Lightning Experience, Lightning Communities, and the mobile app checkbox.

 

  1. Click on Save, as shown in the following screenshot:
  1. Navigate to an Accounts page.
  2. Click on the Setup gear icon.

The Setup gear icon is located in the top right-hand area of the Account page.

  1. Click on Edit Page, as shown in the following screenshot:

After having clicked Edit Page, you will be presented with the Lightning App Builder screen for the Account page, as shown in the following screenshot:

  1. Drag the Visualforce component from the left-hand components pane to the canvas in the top right position.
  2. Select CreditScore in the Visualforce Page Name.
  3. Type Financial Assessment for the Label.
  4. Set the Height (in pixels) field to 50.
  5. Click on Save.
  6. Click on Activation..., as shown in the following screenshot:

If this is the first time you have saved the Account page, instead of the previous step, you will have been presented with a Page Saved dialog. In this scenario, carry out the following steps:

  1. Click on Activate, as shown in the following screenshot:
  2. Click on Assign as Org Default, as shown in the following screenshot:
  3. Click on Save, as shown in the following screenshot:

How it works...

Find an account record and within the Account detail page, enter the value 85 in the custom Credit Score number field.

Navigate from the detail page to the main Account page and refresh the page to reveal the Credit Score image of 85% in the top-right section, as shown in the following screenshot:

Find an account record and, within the Account detail page, enter the value 40 in the custom Credit Score number field.

Navigate from the detail page to the main account page and refresh the page to reveal the Credit Score image of 40% in the top-right section, as shown in the following screenshot:

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Salesforce CRM Admin Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon