You need to sign in to do that
Don't have an account?
santhiya durai
How to disable a Quick Action based on fieldvalue
Hi,
Here is a User case.
As a Contract Manager, User should Archive a record instead of Delete on Item Setup record.
Once a record is Archived, Status field should get updated as Archived and Quick Action should get disabled or user can't Archive a record again.
I have created a Quick Action and Lightning Component. I am calling Lightning Component on click of Action. Status is updating as expected . But I am not sure about disbale a Quick Action when status is Archived. Can anyone help me on this?
Class:
public class ArchiveRecord {
@AuraEnabled
public static void getItemSetupForm(Id itemsetupId){
Item_Setup__c itemsetup= [Select Id, Name,Processed__c,Item_Setup_Form_Status__c from Item_Setup__c where Id=:itemsetupId];
itemsetup.Item_Setup_Form_Status__c='Archived';
update itemsetup;
if(itemsetup.Item_Setup_Form_Status__c=='Archived'){
itemsetup.Name=itemsetup.Name +'_Archived';
}
upsert itemsetup;
}
}
Component:
<aura:component controller="ArchiveRecord" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" access="global">
<aura:html tag="style">
.cuf-content {
padding: 0 0rem !important;
}
.slds-p-around--medium {
padding: 0rem !important;
}
.slds-modal__content{
overflow-y:hidden !important;
height:unset !important;
max-height:unset !important;
}
</aura:html>
<aura:attribute name="showSpinner" type="boolean" />
<aura:attribute name="accessFlag" type="boolean"/>
<aura:attribute name="noAccessFlag" type="boolean"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:if isTrue="{!v.accessFlag}">
<div class="modal-header slds-modal__header slds-size_1-of-1">
<h4 class="title slds-text-heading--medium">Archive Item Setup Form</h4>
</div>
<!--End Modal Header-->
<!--Modal Body-->
<div class="slds-modal__content slds-p-around--x-large slds-align_absolute-center slds-size_1-of-1 slds-is-relative">
<form class="slds-form--stacked">
<div class="slds-align_absolute-center">
<b>Do you want to Archive this record?</b>
</div>
</form>
</div>
<!--End of Modal Body-->
<!--Modal Footer-->
<div class="modal-footer slds-modal__footer slds-size_1-of-1">
<lightning:button variant="Neutral" class="slds-button" label="Cancel" onclick="{!c.cancelBtn}"/>
<lightning:button variant="Brand" class="slds-button" label="Continue" onclick="{!c.updateStatus}"/>
</div>
</aura:if>
</aura:component>
Controller:
({
updateStatus : function(component, event, helper) {
var itemsetupId=component.get("v.recordId");
var action=component.get("c.getItemSetupForm");
action.setParams({"itemsetupId":itemsetupId
});
action.setCallback(this,function(response){
var state=response.getState();
if(state==="SUCCESS"){
let toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "The record Archived Successfully",
"type": "success"
});
toastEvent.fire();
}
else if (state === "ERROR")
{
alert("Failed");
}
var dismissActionPanel = $A.get("e.force:closeQuickAction");
dismissActionPanel.fire();
$A.get('e.force:refreshView').fire();
component.set("v.showSpinner",false);
});
$A.enqueueAction(action);
},
cancelBtn : function(component, event, helper) {
// Close the action panel
var dismissActionPanel = $A.get("e.force:closeQuickAction");
dismissActionPanel.fire();
}
})
Thanks in advance!
Here is a User case.
As a Contract Manager, User should Archive a record instead of Delete on Item Setup record.
Once a record is Archived, Status field should get updated as Archived and Quick Action should get disabled or user can't Archive a record again.
I have created a Quick Action and Lightning Component. I am calling Lightning Component on click of Action. Status is updating as expected . But I am not sure about disbale a Quick Action when status is Archived. Can anyone help me on this?
Class:
public class ArchiveRecord {
@AuraEnabled
public static void getItemSetupForm(Id itemsetupId){
Item_Setup__c itemsetup= [Select Id, Name,Processed__c,Item_Setup_Form_Status__c from Item_Setup__c where Id=:itemsetupId];
itemsetup.Item_Setup_Form_Status__c='Archived';
update itemsetup;
if(itemsetup.Item_Setup_Form_Status__c=='Archived'){
itemsetup.Name=itemsetup.Name +'_Archived';
}
upsert itemsetup;
}
}
Component:
<aura:component controller="ArchiveRecord" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" access="global">
<aura:html tag="style">
.cuf-content {
padding: 0 0rem !important;
}
.slds-p-around--medium {
padding: 0rem !important;
}
.slds-modal__content{
overflow-y:hidden !important;
height:unset !important;
max-height:unset !important;
}
</aura:html>
<aura:attribute name="showSpinner" type="boolean" />
<aura:attribute name="accessFlag" type="boolean"/>
<aura:attribute name="noAccessFlag" type="boolean"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:if isTrue="{!v.accessFlag}">
<div class="modal-header slds-modal__header slds-size_1-of-1">
<h4 class="title slds-text-heading--medium">Archive Item Setup Form</h4>
</div>
<!--End Modal Header-->
<!--Modal Body-->
<div class="slds-modal__content slds-p-around--x-large slds-align_absolute-center slds-size_1-of-1 slds-is-relative">
<form class="slds-form--stacked">
<div class="slds-align_absolute-center">
<b>Do you want to Archive this record?</b>
</div>
</form>
</div>
<!--End of Modal Body-->
<!--Modal Footer-->
<div class="modal-footer slds-modal__footer slds-size_1-of-1">
<lightning:button variant="Neutral" class="slds-button" label="Cancel" onclick="{!c.cancelBtn}"/>
<lightning:button variant="Brand" class="slds-button" label="Continue" onclick="{!c.updateStatus}"/>
</div>
</aura:if>
</aura:component>
Controller:
({
updateStatus : function(component, event, helper) {
var itemsetupId=component.get("v.recordId");
var action=component.get("c.getItemSetupForm");
action.setParams({"itemsetupId":itemsetupId
});
action.setCallback(this,function(response){
var state=response.getState();
if(state==="SUCCESS"){
let toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "The record Archived Successfully",
"type": "success"
});
toastEvent.fire();
}
else if (state === "ERROR")
{
alert("Failed");
}
var dismissActionPanel = $A.get("e.force:closeQuickAction");
dismissActionPanel.fire();
$A.get('e.force:refreshView').fire();
component.set("v.showSpinner",false);
});
$A.enqueueAction(action);
},
cancelBtn : function(component, event, helper) {
// Close the action panel
var dismissActionPanel = $A.get("e.force:closeQuickAction");
dismissActionPanel.fire();
}
})
Thanks in advance!
Greetings!
I would suggest you to use ui:button to achieve your requirement.
Please refer the below threads for the sample code and how you can achieve this based on the profile/pagelayout.
https://salesforce.stackexchange.com/questions/219366/ability-to-disabled-a-quick-action-lightning-button
https://salesforce.stackexchange.com/questions/241242/is-it-possible-to-show-hide-or-enable-disable-a-lightning-quick-action
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri