You need to sign in to do that
Don't have an account?
Kamal Thakur
Update Record using Lightning Button
I am opening a Lightning App on a button Click (via URL). The App updates Description field on Contact Object. Below is my code -
ConApp
conAppCmp
conAppCmpController.js
myControl
I don't know what is causing the problem.
ConApp
<aura:application > <aura:attribute name="id" type="String"/> hi {!v.id} <c:ConAppCmp conid="{!v.id}" /> </aura:application>
conAppCmp
<aura:component controller="MyControl"> <aura:attribute name="conObj" type="Contact" /> <aura:attribute name="conid" type="String"/> <p>hi {!v.conid}</p> <aura:attribute name="replaceProducts" type="List" default="['red','blue']"/> <ui:inputSelect aura:id="levels" label="Available Replacements"> <aura:iteration items="{!v.replaceProducts}" var="level"> <ui:inputSelectOption text="{!level}" value="{!v.conObj.Description}" label="{!level}"/> </aura:iteration> </ui:inputSelect> <lightning:button variant="brand" label="Submit" onclick="{! c.handleClick }" /> </aura:component>
conAppCmpController.js
({ handleClick : function(component, event, helper) { var newAcc = component.get("v.conObj"); var action = component.get("c.saveRecord"); action.setParams({ "acc": newAcc }); action.setCallback(this, function(a) { var state = a.getState(); if (state === "SUCCESS") { var name = a.getReturnValue(); alert("hello from here"+name); } }); $A.enqueueAction(action) } })
myControl
public with sharing class MyControl { @AuraEnabled public static Contact saveRecord(Contact acc) { upsert acc; return acc; } }Button Contains this URL -
/c/ConApp.app?id={!Contact.Id}
I don't know what is causing the problem.
It seems, you are not able to get selected value on button click. Please correct me if i am wrong.
To get selected value, create an attribute which will bind to your picklist and then get in controller using that attribute like below
conAppCmp
conAppCmpController.js Kindly let me know if this works for you.
All Answers
It seems, you are not able to get selected value on button click. Please correct me if i am wrong.
To get selected value, create an attribute which will bind to your picklist and then get in controller using that attribute like below
conAppCmp
conAppCmpController.js Kindly let me know if this works for you.