Last active
September 17, 2022 00:53
-
-
Save JitendraZaa/972516dd00f208e95232a0d2c2639f66 to your computer and use it in GitHub Desktop.
Show hide Loading Image in Lightning Web Component and call Apex Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .hidemodel{ | |
| display: none; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <span class={cssDisplay}> | |
| <div id="spinnerDiv" class="demo-only demo--inverse" style="height: 10rem"> | |
| <div class="slds-spinner_container"> | |
| <div role="status" class="slds-spinner slds-spinner_medium"> | |
| <span class="slds-assistive-text">Loading</span> | |
| <div class="slds-spinner__dot-a"></div> | |
| <div class="slds-spinner__dot-b"></div> | |
| </div> | |
| </div> | |
| </div> | |
| </span> | |
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { LightningElement,wire, track } from 'lwc'; | |
| import isMoreThan10k from '@salesforce/apex/HybridAccountViewController.isMoreThan10k'; | |
| export default class HybridAccountView extends LightningElement { | |
| @track cssDisplay = ''; | |
| @wire(isMoreThan10k) | |
| returnedFlag( response, error){ | |
| if(response && response.data === 'Yes'){ | |
| this.cssDisplay = 'hidemodel'; | |
| } | |
| else if(response && response.data === 'No'){ | |
| window.location.replace("Some URL to redirect if account assigned are low"); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="hybridAccountView"> | |
| <apiVersion>45.0</apiVersion> | |
| <isExposed>True</isExposed> | |
| <masterLabel>Hybrid Account View</masterLabel> | |
| <description>LWC to take decision which Account view to show </description> | |
| <targets> | |
| <target>lightning__RecordPage</target> | |
| <target>lightning__AppPage</target> | |
| <target>lightning__HomePage</target> | |
| </targets> | |
| </LightningComponentBundle> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @Date : Feb 28 2019 | |
| * @Author : Jitendra Zaa | |
| * @Description : Logic to decide Hybrid Account View | |
| * | |
| * */ | |
| public with sharing class HybridAccountViewController { | |
| @AuraEnabled(cacheable=true) | |
| public static String isMoreThan10k() { | |
| //Check if session Cache exists | |
| //If Session Cache contains '1' means user has 10k records | |
| if (Cache.Session.contains(UserInfo.getUserId())) { | |
| String isMoreThan10k = (String)Cache.Session.get(UserInfo.getUserId()); | |
| if(isMoreThan10k == 'Yes'){ | |
| return 'Yes'; | |
| } | |
| return 'No'; | |
| } | |
| //Cant use aggregated query to with LIMIT, not good practice to fetch all record | |
| //If cache does not exists then query SFDC | |
| List<Account> lsAcc = [Select Id FROM Account WHERE OwnerId = :UserInfo.getUserId() LIMIT 10001]; | |
| if(lsAcc.Size() > 10000){ | |
| Cache.Session.put(UserInfo.getUserId(), 'Yes'); | |
| return 'Yes'; | |
| } | |
| Cache.Session.put(UserInfo.getUserId(), 'No'); | |
| return 'No'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment