You need to sign in to do that
Don't have an account?
Ryan Werner 22
Checking if a string contains or is "like" a value
Hello-
We have a junior developer who wrote a very large lightning component that has over 1,000 references to:
<aura:if isTrue="{!v.profileName =='System Administrator'}"
The issue we have is now we need additional profiles, all containing "Admin" in the name to this. Is there a way to copy/replace all so I don't have to go through each individual reference and add || or && conditions to it? Is something like this doable:
<aura:if isTrue="{!CONTAINS(v.profileName, 'Admin'}"
or
<aura:if isTrue="{!v.profileName == '%Admin'}"
In some cases we may need an || condition in some cases we may need an && condition. So i cannot just to a global replace to add the additional profile names here.
Thanks
We have a junior developer who wrote a very large lightning component that has over 1,000 references to:
<aura:if isTrue="{!v.profileName =='System Administrator'}"
The issue we have is now we need additional profiles, all containing "Admin" in the name to this. Is there a way to copy/replace all so I don't have to go through each individual reference and add || or && conditions to it? Is something like this doable:
<aura:if isTrue="{!CONTAINS(v.profileName, 'Admin'}"
or
<aura:if isTrue="{!v.profileName == '%Admin'}"
In some cases we may need an || condition in some cases we may need an && condition. So i cannot just to a global replace to add the additional profile names here.
Thanks
and you have to replace the variable that you set in the controller with the current condition mentioned aboce. Copy code to text pad, replace with variable and paste back to IDE or console.
We can't directly use the CONTAINS function in aura:if . But we have some workaround it's still in salesforce idea
https://trailblazer.salesforce.com/ideaView?id=0873A000000CSTAQA4
Refer the below links for workaround:
https://sfdcmonkey.com/2018/01/06/workaround-for-contains-lightning-component/
https://gist.github.com/samuel-alves/b6e43a3d88bfaa1af0853002ffdc0962
Thanks,
Maharajan.C
Refer the below links.
For Aura - https://sfdcmonkey.com/2018/01/06/workaround-for-contains-lightning-component/
And If you want only profile that contains 'Admin' you can query In apex like below.
SELECT Id, Name, UserType FROM Profile WHERE Name Like '%Admin%'
let me know if it helps you and marking it as best so that it can help to others in future.
Thank you