• Himanshu Tak
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi, 

I am trying to create a Lightning Component to that has a functionality to update a field value(Submit_Go_No_Go_Question__c), and hide the button whenever a field (Go_No_Go_Question__c) is not blank.

Here is my existing code

Apex:
public class addGNGQuestion {
    
    @AuraEnabled
    public static void updateChk(String key){
        Opportunity acc = [SELECT Id, Name, Submit_Go_No_Go_Question__c, Go_No_Go_Question__c FROM Opportunity WHERE Id=:key];  
        if(acc.Go_No_Go_Question__c == null){
            acc.Submit_Go_No_Go_Question__c = true;
        }
        UPDATE acc;
    }
}

Component:
<aura:component controller="addGNGQuestion"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:handler event="force:refreshView" action="{!c.isRefreshed}" />
    <div class="slds-align_absolute-center" style="height:12rem">
    <lightning:button variant="brand" 
                      label="Add Go-No Go Question" 
                      onclick="{!c.updateCheck}" 
                      aura:id="disablebuttonid" />
        </div>
</aura:component>

Controller:
({
    updateCheck : function(component, event, helper) {
        var rid = component.get("v.recordId");
        var action = component.get("c.updateChk");
        action.setParams({key : rid});
        action.setCallback(this, function(response) {
            var state = response.getState();
            
         let button = component.find('disablebuttonid');  
                 if(acc.Go_No_Go_Question__c != null){
            button.set('v.disabled',true)
            }
            
            if (state === "SUCCESS") {
                $A.get('e.force:refreshView').fire();  
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                } 
                else {
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },
})
Helper:
({
    updateCheck11_helper : function(c,e,h) {
        alert('Success!');
        var save_action = c.get("c.updateCheck");
        save_action.setParams({
            });
        $A.enqueueAction(save_action);
    }
})
Any help is much appreciated.