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
niki s 7niki s 7 

Pass data from js to apex

Hello I am creating an ui for account. It contains 2 fields name and city. There will be a button which will display list of account. Now while passing values from js to apex getting name as null but in alert it's showing the value 
Suraj Tripathi 47Suraj Tripathi 47
Hi niki s 7,
Here is the solution:

Aura Component:
<aura:component controller="Accountsfields">
    <aura:attribute name="Name" type="String" />
    <aura:attribute name="City" type="String"/>
    <div class="slds-p-around_small">
        <header class="slds-modal__header">
            <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate"> <lightning:icon iconName="standard:account" alternativeText="Account" title="Account" /><b> Account</b></h2>
        <lightning:input type="Text" aura:id="namefield" label="Name" value="{!v.Name}"/>
        <lightning:input type="text" aura:id="cityfield" label="City" value="{!v.City}"/>
        <footer class="slds-modal__footer slds-align_absolute-center">
                        <lightning:button label="Save" iconPosition="left"   variant="brand" onclick="{!c.doSave}"/>

    doSave: function(c,e,h){
        var name  = c.get("v.Name");
        var city  = c.get("v.City");
       let action = c.get("c.getaccountfields");
            "Name" : name,
             "city" : city
        action.setCallback(this, function(response){
            let state = response.getState();
            if(state === "SUCCESS"){
                var result = response.getReturnValue();

Apex Class:

public class Accountsfields {
     public static string getaccountfields(string Name, string city){
         system.debug('Name'+ Name);
         system.debug('City'+ city);
            return Name ;
        }catch(exception e){
           return null;