![Salesforce CRM Admin Cookbook(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/376/36700376/b_36700376.jpg)
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:
- Click on the Setup gear icon, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_203.jpg?sign=1739599409-NS3hARt9cH456ZQxm2Ej0dy1KiiUuz7s-0-aab128177ac8e589be698d2c444c1f69)
The Setup gear icon is located in the top right-hand area of the main Home page.
- Click the Developer Console option, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_398.jpg?sign=1739599409-fLu8wGCAKWDU7lPWYVTuwgrFfJs44Axp-0-1aa753fec1bfae4443e02816e727c4e1)
- In the resulting Developer Console window, click on File.
- Click on New.
- Click on the Visualforce Page, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_109.jpg?sign=1739599409-GoaLRLrVdNV2BVPZIxsnY7klufQ38iRH-0-42b064896ff0a068f73a93470c352929)
We will be presented with a New Apex Page dialog.
- Enter CreditScore for the name of your new Apex Page.
- Click on OK, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_159.jpg?sign=1739599409-LYbZoqymn8xs6GQ45B1rYJQkcNAdO24c-0-5167ed32786c320a625821140d7ead56)
- 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"> </td>'; else sHTML += '<td class="grey" nowrap="nowrap">
</td>'; }else{ if( i<iLimit ) sHTML += '<td class="green" nowrap="nowrap">
</td>'; else sHTML += '<td class="grey" nowrap="nowrap">
</td>'; } } sHTML += '<td class="no_border">100%</td></tr></table>'; if( iLimit >= 0 ){ document.getElementById("CreditScore").innerHTML = sHTML +
"Credit Score : " + iLimit + "%"; } }); </script> <p id="CreditScore">Credit Score is not within limits</p> </apex:page>
- Click on File.
- Click on Save, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_17.jpg?sign=1739599409-Qafhq3VMGIUq8nX3LMmft2NBI9XB3xbG-0-192f46c70ee96d38e5f0d56d845e2df4)
Now set the profile security and Lightning accessibility settings for the Visualforce page by carrying out the following steps:
- Click on the Setup gear icon, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_155.jpg?sign=1739599409-0aJvuwO5dDJQ3gRBSaAE1OslRgD4svMc-0-8aae030ec8d4c10380306d07a9b6ad2b)
The Setup gear icon is located in the top right-hand area of the main Home page.
- Click the Setup option, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_192.jpg?sign=1739599409-koc6TjNdzaF2Gw3JNb936shNFMjYLlyl-0-c8f3add27523455568f213851c9bfc72)
- Type the text visualforce in the Quick Find search box, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_49.jpg?sign=1739599409-Kwpu2v6bODGr9hsb2KqENUacpKhFXeOi-0-dac8f6dc0f575ced9965791ca1f4c40e)
- Click on Visualforce Pages.
- Click on Security for the CreditScore Visualforce Page.
- Click on Save.
- Click on Edit.
- Check the Available for Lightning Experience, Lightning Communities, and the mobile app checkbox.
- Click on Save, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_100.jpg?sign=1739599409-6m1CK6QyaPSkDlfWua9MiRaMfACLkpNb-0-bd4e69a7ea6e505aae1dcfb6911127d0)
- Navigate to an Accounts page.
- Click on the Setup gear icon.
The Setup gear icon is located in the top right-hand area of the Account page.
- Click on Edit Page, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_99.jpg?sign=1739599409-t5JfvMzX3w1eGXiufCrQw5EA1w4rpXp4-0-47b767af61361ce3305cd670790bbe61)
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:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_70.jpg?sign=1739599409-bCu7hIaRE80WbKOwUghWvsUiazUjGPa9-0-6885505ca3ebc0aa28dda23cd5c518a5)
- Drag the Visualforce component from the left-hand components pane to the canvas in the top right position.
- Select CreditScore in the Visualforce Page Name.
- Type Financial Assessment for the Label.
- Set the Height (in pixels) field to 50.
- Click on Save.
- Click on Activation..., as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_392.jpg?sign=1739599409-M8FwZ5tkAiyZWaucJ0AkIBEN6g4GhVJJ-0-4f5b08beb5ecc3a5a333f617424ff10a)
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:
- Click on Activate, as shown in the following screenshot:
- Click on Assign as Org Default, as shown in the following screenshot:
- Click on Save, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/F5F0D9/19470399608916606/epubprivate/OEBPS/Images/Chapter_423.jpg?sign=1739599409-ossZUM24y4ohbPoiROH9nONuQ9MxkgfF-0-2caf0e8a2a81037d3b615053d237f854)