![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=1739534022-PC1Go0SaahbkXujEiSnT5vEtJIb22uxf-0-3a9a50c687052e930680357b65fa886f)
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=1739534022-3RX5iQlAMCvqU4dlnNIUmNt2ZwjMSeCL-0-9647d5b455c682ba098013a74faeb11c)
- 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=1739534022-4vhb523YGHx4GIYoaReHc9q12pQxHvOs-0-6d05c5deae57194f434e4c03cf464314)
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=1739534022-EpsA4Xd4hPP1XVmnkwpDTunF7OGNyat8-0-d0ecf8b7a867a5547ece275c4c2aa329)
- 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=1739534022-FmHJpKCVBYrYvpISJw0iXhfszkx0dBNl-0-1604ca387cfdfed5b8e0b2ef7b9f0cad)
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=1739534022-5HKT2sQ7pQc0RP0DmIFRfxZsgvbtXQ09-0-14a97457de036c8512efee2bf14ae3a5)
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=1739534022-Qwzo581kIgcffwesvzMphsq53HtBJHRv-0-3cfaea165ac4a90d04beb0e01d5b20bf)
- 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=1739534022-kW1GzXa0czU4op2jr78a54vIWieirU6o-0-fd8f3b836b76617b0e8e5b2c6833b561)
- 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=1739534022-Wmoq1tLiMTHrci7bcUAvUOKrpAR1zr7E-0-1eb74799ab3125966e7f17af0ff9605d)
- 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=1739534022-uoDX5UrPu3JeUvsa1GubtA9GgWUqXTb3-0-8b9bb71982cc6a0a24de00dd4371fe32)
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=1739534022-s5Rf68v0AIQe1PWUDXHUPdDLYdsPWeys-0-05702e6b07a2dbeca1c3716c5297db68)
- 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=1739534022-RtvWIrgyzhGptBHSiO7yz7UBlLIbkfyM-0-461a790ac5cd1bae55cb8c3840a8047e)
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=1739534022-5zYvmMcxl3lRqQdufjOhwU3ybTVxL1YN-0-e28ef41c6f7db7f7593a1c0be9001fef)