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
billing badgebilling badge 

how to pass lightning:inputfield onchange value to apex controller

<aura:attirbute name="LeadObj" type="Lead"/>
<lightning:recordEditForm objectApiName="Lead" >
    <lightning:inputField aura:id="accid" fieldName="Account__c" value="{!v.LeadObj.Account__c}" label="Attribute" onchange="{!c.myChangeAcc}"/>
</lightning:recordEditForm>



controller.js

mychangeAcc:function(component,event,helper){
var acc=component.find('accid').get('v.value');
alert(acc);
var action = component.get("c.LeadAccountInfo");

        action.setParams({ldvalue:acc});

}

apex class:

@AuraEnabled
    public static string LeadAccountInfo(Id ldvalue){
Account ac=[select id,Name from Account where Id =:ldvalue limit 1];
        return ac.Name;
}

Hi All ,here in thee above acode it is not passing parameter to apex class. if i test with harcoded id its working 

can anyone help

Thanks,
Billing Badge
{tushar-sharma}{tushar-sharma}
I believe you get the data in JS controller, So now call the apex we follow
var action  = component.get("c.LeadAccountInfo");
        action.setParams({
                "Idvalue" : acc
            });
        action.setCallback(this, function(response){
            var status = response.getState();
            if(status === "SUCCESS"){
               console.log( response.getReturnValue() );
            }
        });
        
        $A.enqueueAction(action);

If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/
billing badgebilling badge
Thanks for the response thanu sharma
its not working stil
{tushar-sharma}{tushar-sharma}
Are you getting value in JS controller? Did you get any exception/error? Can you explain what is not working here?
billing badgebilling badge
am getting exception below
Error message: Value provided is invalid for action parameter 'ldvalue' of type 'Id'
{tushar-sharma}{tushar-sharma}
try to change Id to type String. Or what you are getting in alert(acc);
Shagufta NooriShagufta Noori
As I am using Blogger for hosting my blog so I am not having this issue.
For Latest  हिंदी में सरकारी नौकरी तथा सरकारी योजनाएं (https://www.sarkarisamachar.in/)
yogeshRaoyogeshRao
Idvalue should be of type String

@AuraEnabled public static string LeadAccountInfo(String ldvalue)
{
Account ac=[select id,Name from Account where Id =:ldvalue limit 1];
return ac.Name;
}

Thanks Yogesh