• TestsalesforceAccount
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
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;
    }
}

 
can you please anyone help me how to write test class for below code.

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];
            system.debug('=='+lstOfStd);
        }   
         
        if(!lstOfStd.isEmpty()){
            return lstOfStd.get(0);
        }
         
        
        return null;
    }
}
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;
    }
}

 
can you please anyone help me how to write test class for below code.

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];
            system.debug('=='+lstOfStd);
        }   
         
        if(!lstOfStd.isEmpty()){
            return lstOfStd.get(0);
        }
         
        
        return null;
    }
}