+ Start a Discussion
Pooja NekkalapudiPooja Nekkalapudi 

lightning component: update a record on click of button

I would like to update a check box to true when a button is pressed on a custom object, how do I do this using lightning component
Will add more records to update later, Any help is apreciated as i am ne to lightning
Ajay K DubediAjay K Dubedi
Hi Pooja,
Follow some given steps:
Component:

<aura:component controller="updateCheckBoxPlan">
    <aura:attribute name="updateCheckBox" type="Plan__c" default="{'sobjectType':'Plan__c'}"/>
	<lightning:button variant="brand" label="Update A Check Box As True" onclick="{!c.updateCheck11}"  />
</aura:component>

Controller:

({
	updateCheck11 : function(c, e, h) {
		h.updateCheck11_helper(c,e,h);
	},
})

Helper:

({
	updateCheck11_helper : function(c,e,h) {
        alert('sdfsd');
		var save_action = c.get("c.updateCheck");
    	save_action.setParams({
            });
        $A.enqueueAction(save_action);
	}
})

Class: 

public class updateCheckBoxPlan {
    @AuraEnabled
	public static void updateCheck(){
        list<Plan__c> Pl_list = new list<Plan__c>();
        pl_list = [select id,Valid__c from Plan__c Limit 1];
        Plan__c p =new Plan__c();
        p.id=pl_list[0].id;
        p.Valid__c=true;
        update p;
    }
}
I hope it will help you!!
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.

Regards,
Ajay
 
Pratima Shrivastav 3Pratima Shrivastav 3
Hi Pooja,
I had a similar scenario. I posted here on how to create a component for this scenario.
http://trail.withneha.com/convert-my-javascript-button-to-lightning-quick-action/
The new LearnerThe new Learner
Hi Ajay,

I have added ur code , i am nto sure how to add to the pagealyout can you help me