![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=1739423491-BCqEMZkvpA82l1C9GAABut4xHfZhw25h-0-fc94d55a56666b5fcf0938b25c03c0f7)
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=1739423491-5uk5uTOOhGnhjiS6hv4dcb2ayfUkv1fm-0-ed08a696e763e15bd8a20ba11978403b)
- 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=1739423491-BGEXPlkbPx0N6KqfAEn0zDlomY9E3pK7-0-c5e027b7cef76e83d5f69298e8e6b64f)
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=1739423491-7GxWNBtyitxhlcnTb5FZDpnJNhvJKKHI-0-101de14b427c0de257fb0f26693c9a01)
- 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=1739423491-OXzm5crTVgz2pp8B6afzgNl4OkvlQsUW-0-6f13ac08b994581370d75b8cc9353751)
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=1739423491-7Avhhu4aCcvgs6FDwH157ze8Z8mtE82S-0-cd54b91cce3d73bed8c519d6d7c7c3d8)
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=1739423491-SCKBWYYwMHDp29oJJxzHP3mWctzAfQBc-0-0030df59e8c54db87b0542ac010985b7)
- 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=1739423491-H0nYSG3pf2vWn0eeno9s3WYGsLIIF6E1-0-04c0688fc025cac31ae8db1be7f2dfed)
- 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=1739423491-HS6HEnaL0L8qX6cfIiLq6jhEcB588ITR-0-12c4d487f2051221a5f5778f0a06ad9d)
- 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=1739423491-iPsbLoZybokn6WPejuQFbV8q9iB0qtJM-0-ee6ef58b9fb32f2129d122c0d2a10094)
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=1739423491-liMCgZI5kDhfBj4nnRTCyYTTv1qeqA0g-0-5e8f8a5587f08eb260bf0c82e8a0ece9)
- 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=1739423491-Sv3Us1ocybQHoq4nhhOBJkMWZdKk8uPW-0-2cecbd0a250f5d93eecb8a2f69ea83de)
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=1739423491-zG3nUoGcgOaHUH7CHkFjxD6RNNVhMlmW-0-84aec087820863b6d35c9118a4019f6a)