function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TestsalesforceAccountTestsalesforceAccount 

How set default set value in component

Hi Folks,

I have created one lightning component button. once submit the button  enebled three checkbox fileds in record level. once enabled checboxes after clik on buttion three checkboxes enabled at component level  how set default checkboxes false at component level always even it is enbled at record level.
can you please help me how to fix this one. Thanks in advance.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" controller="UpdateOpptyController">
    <!-- Attribute declaration -->
   
    <aura:attribute name="opptyObj" type="Opportunity" default="{ 'sobjectType': 'Opportunity'}"/>
     
    <!-- hadlerMethod declaration -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
       <div class="slds-form-element"> <ui:inputCheckbox aura:id="checkbox" label="Assay Transition Date" value="{!v.opptyObj.checkbox1}" /></div>
    <div class="slds-form-element"><ui:inputCheckbox aura:id="checkbox" label="Instrument Install Date" value="{!v.opptyObj.checkbox2}" /></div>
    <div class="slds-form-element"><ui:inputCheckbox aura:id="checkbox" label=" TOR Date" value="{!v.opptyObj.checkbox3}"/></div>
    <br/>
    <!-- Button -->
    <div class="slds-form-element">
        <lightning:button aura:id="saveId"
                          label="Save"
                          variant="brand"
                          onclick="{!c.doSave}"/>
    </div>
        
           
</aura:component>
==============================

({
   
    doInit : function(component, event, helper) {
        
        //Calling server side controller's fetchOpportunityDetails() method.
        var action = component.get("c.fetchOpportunityDetails");
        action.setParams({"oppId": component.get("v.recordId")});
        
        action.setCallback(this, function(response){
            //<response.getState()> return response status as SUCCESS/ERROR/INCOMPLETE etc.
            var state = response.getState();
            console.log("state="+state)
            //If response from server side is <SUCCESS>, then we will set the component attribute "studentObj".
            if (state === "SUCCESS"){
                var responseOpportunityRecord = response.getReturnValue();
                component.set("v.opptyObj", responseOpportunityRecord);
            }else if (state === "INCOMPLETE") {
                //Offline message display logic.
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "OFFLINE!",
                    "message": "You are in offline."
                });
                toastEvent.fire();
            }else if (state === "ERROR") {
                //Error message display logic.
                var errors = response.getError();
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "ERROR!",
                    "message": errors[0].message
                });
                toastEvent.fire();
            }else {
                //Unknown message display logic.
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "UNKOWN!",
                    "message": "Unknown error."
                });
                toastEvent.fire();
            }
        });
        
        $A.enqueueAction(action);
    },
    
    
    doCancel : function(component, event, helper) {
        var cmpTargetForEdit = component.find('modalIdForEditStudent');
        var cmpBackDropForEdit = component.find('backdropIdForEditStudent');
        $A.util.removeClass(cmpBackDropForEdit,'slds-backdrop--open');
        $A.util.removeClass(cmpTargetForEdit, 'slds-fade-in-open');
    },
    
    
    doSave : function(component, event, helper) {
  
        var action = component.get("c.updateOpportunity");
        //Set method parameter of updateOpportunity() method.
        action.setParams({"oppty": component.get("v.opptyObj")});
        
        action.setCallback(this, function(response){
            //<response.getState()> return response status as SUCCESS/ERROR/INCOMPLETE etc.
            var state = response.getState();
            console.log("state="+state)
            //If response from server side is <SUCCESS>, then we will display a success message.
            if (state === "SUCCESS"){
                //Success message display logic.
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Success!",
                    "message": "Opportunity record has been updated successfully."
                });
                toastEvent.fire();
                
                //Navigate to detail page.
                window.location ="/"+component.get("v.recordId");
            }else if (state === "INCOMPLETE") {
                //Offline message display logic.
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "OFFLINE!",
                    "message": "You are in offline."
                });
                toastEvent.fire();
            }else if (state === "ERROR") {
                //Error message display logic.
                var errors = response.getError();
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "ERROR!",
                    "message": errors[0].message
                });
                toastEvent.fire();
            }else {
                //Unknown message display logic.
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "UNKOWN!",
                    "message": "Unknown error."
                });
                toastEvent.fire();
            }
        });
        
        $A.enqueueAction(action);
 }
})

public class UpdateOpptyController {

    @AuraEnabled
    public static void updateOpportunity(Opportunity oppty){
        UPDATE oppty;
    }
    
      @AuraEnabled
    public static Opportunity fetchOpportunityDetails(Id oppId) {
        List<Opportunity> lstOfStd = new List<Opportunity>();
        system.debug('=='+oppId);
        if(oppId != null) {
            lstOfStd = [SELECT Id, Name,CheckBox1,CheckBox12,CheckBox3 FROM Opportunity WHERE Id = :oppId];
            system.debug('=='+lstOfStd);
        }   
         
        if(!lstOfStd.isEmpty()){
            return lstOfStd.get(0);
        }
         
        
        return null;
    }
}

 
Raj VakatiRaj Vakati
Change your apex class as below .. No need to change CMp
 
public class UpdateOpptyController {

    @AuraEnabled
    public static void updateOpportunity(Opportunity oppty){
        UPDATE oppty;
    }
    
      @AuraEnabled
    public static Opportunity fetchOpportunityDetails(Id oppId) {
        List<Opportunity> lstOfStd = new List<Opportunity>();
        system.debug('=='+oppId);
        if(oppId != null) {
            lstOfStd = [SELECT Id, Name,CheckBox1,CheckBox12,CheckBox3 FROM Opportunity WHERE Id = :oppId];
			lstOfStd.CheckBox1__c = false ; 
			lstOfStd.CheckBox12 = false ; 
			lstOfStd.CheckBox3 = false ; 
			
            system.debug('=='+lstOfStd);
        }   
         
        if(!lstOfStd.isEmpty()){
            return lstOfStd.get(0);
        }
         
        
        return null;
    }
}

 
TestsalesforceAccountTestsalesforceAccount
HI rajamohan , Thank you so much for quick response I got below error Variable does not exist: Checkbox1
Raj VakatiRaj Vakati
Try this code pls ..  Change API names for checkbox 1 ,2 ,3
 
public class UpdateOpptyController {

    @AuraEnabled
    public static void updateOpportunity(Opportunity oppty){
        UPDATE oppty;
    }
    
      @AuraEnabled
    public static Opportunity fetchOpportunityDetails(Id oppId) {
        List<Opportunity> lstOfStd = new List<Opportunity>();
        system.debug('=='+oppId);
        if(oppId != null) {
            lstOfStd = [SELECT Id, Name,CheckBox1__c ,CheckBox2__c ,CheckBox3__c FROM Opportunity WHERE Id = :oppId];
		lstOfStd.CheckBox1__c = false ; 
			lstOfStd.CheckBox2__c = false ; 
			lstOfStd.CheckBox3__c = false ; 
		
            system.debug('=='+lstOfStd);
        }   
         
        if(!lstOfStd.isEmpty()){
            return lstOfStd.get(0);
        }
         
        
        return null;
    }
}

 
TestsalesforceAccountTestsalesforceAccount
Hi Rajamohan, I am using API names only but i am getting error. Thanks
Raj VakatiRaj Vakati
public class UpdateOpptyController {

    @AuraEnabled
    public static void updateOpportunity(Opportunity oppty){
        UPDATE oppty;
    }
    
      @AuraEnabled
    public static Opportunity fetchOpportunityDetails(Id oppId) {
         Opportunity   lstOfStd = [SELECT Id, Name,CheckBox1__c ,CheckBox2__c ,CheckBox3__c FROM Opportunity WHERE Id = :oppId];
		lstOfStd.CheckBox1__c = false ; 
			lstOfStd.CheckBox2__c = false ; 
			lstOfStd.CheckBox3__c = false ; 
		
            system.debug('=='+lstOfStd);
			
			return lstOfStd
        
        
    }
}