You need to sign in to do that
Don't have an account?
TestsalesforceAccount
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;
}
}
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 Vakati
Change your apex class as below .. No need to change CMp
TestsalesforceAccount
HI rajamohan ,
Thank you so much for quick response
I got below error
Variable does not exist: Checkbox1
Raj Vakati
Try this code pls .. Change API names for checkbox 1 ,2 ,3
TestsalesforceAccount
Hi Rajamohan,
I am using API names only but i am getting error.
Thanks
Raj Vakati