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
Anu Singh 40Anu Singh 40 

how to insert number of employee field value in Account object using aura lightning comonent

Best Answer chosen by Anu Singh 40
Suraj Tripathi 47Suraj Tripathi 47
Hi Anu Singh 40,
This is solution for your question.

Apex Class
public class Question1ControllerClass {
    @AuraEnabled
    public static Boolean insertAccount(String acc) {
        Account accObj = (Account) JSON.deserialize(acc, Account.class);
       Database.SaveResult result = Database.insert(accObj, false);
        
        
        System.debug('-->'+accObj+'-----'+result);
        if(result.isSuccess())
            return true;
        else
            return false;
    }
}
Lightning Code.
<aura:component controller="Question1ControllerClass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <!--aura:attribute name="AccountObj" type="Account" default="{'sObject':'Account'}" /-->
    <aura:attribute name="accountName" type="String"/>
    <aura:attribute name="accountNumOfEmployee" type="Integer"/>
    
    <div class="slds-m-top_medium slds-m-bottom_x-large">
        <div class="slds-p-around_medium lgc-bg">
            
            <lightning:input type="text" label="Account Name" placeholder="type here..." value="{! v.accountName }" aura:id="accName" required="True"/>
        </div>
        
        <div class="slds-p-around_medium lgc-bg">
            
            <lightning:input type="text" label="Account No. Of Employee " placeholder="type here..." value="{! v.accountNumber }" aura:id="accName"/>
        </div>
    </div>
    <div class="slds-m-top_small slds-m-bottom_medium">
        <lightning:button variant="brand" label="INSERT" onclick="{! c.handleClick }" class="slds-m-left_x-small"/>
    </div>
</aura:component>
JS Controller
({
	handleClick : function(component, event, helper) {
		let action = component.get('c.insertAccount');
        var account = new Object();
        
        account.Name = component.get('v.accountName');
        account.NumberOfEmployees = component.get('v.accountNumOfEmployee');
       
        
        action.setParams({
            acc: JSON.stringify(account)
        });
        action.setCallback(this, function(response){
            let res = response.getReturnValue();
            alert(res);
        });
       // console.log(component.find('accName').get('v.value'));
        $A.enqueueAction(action);
	}
})

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Suraj Tripathi
 

All Answers

techrotsz techrotsztechrotsz techrotsz
They have a dire message … International moving is a difficult StuffRoots undertaking. You need to zero in on more than a certain something. You're zeroing in on pressing, As well as you need to control your movers and packers what to do. Extraordinary compared to other tip I can give you is that you
Suraj Tripathi 47Suraj Tripathi 47
Hi Anu Singh 40,
This is solution for your question.

Apex Class
public class Question1ControllerClass {
    @AuraEnabled
    public static Boolean insertAccount(String acc) {
        Account accObj = (Account) JSON.deserialize(acc, Account.class);
       Database.SaveResult result = Database.insert(accObj, false);
        
        
        System.debug('-->'+accObj+'-----'+result);
        if(result.isSuccess())
            return true;
        else
            return false;
    }
}
Lightning Code.
<aura:component controller="Question1ControllerClass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <!--aura:attribute name="AccountObj" type="Account" default="{'sObject':'Account'}" /-->
    <aura:attribute name="accountName" type="String"/>
    <aura:attribute name="accountNumOfEmployee" type="Integer"/>
    
    <div class="slds-m-top_medium slds-m-bottom_x-large">
        <div class="slds-p-around_medium lgc-bg">
            
            <lightning:input type="text" label="Account Name" placeholder="type here..." value="{! v.accountName }" aura:id="accName" required="True"/>
        </div>
        
        <div class="slds-p-around_medium lgc-bg">
            
            <lightning:input type="text" label="Account No. Of Employee " placeholder="type here..." value="{! v.accountNumber }" aura:id="accName"/>
        </div>
    </div>
    <div class="slds-m-top_small slds-m-bottom_medium">
        <lightning:button variant="brand" label="INSERT" onclick="{! c.handleClick }" class="slds-m-left_x-small"/>
    </div>
</aura:component>
JS Controller
({
	handleClick : function(component, event, helper) {
		let action = component.get('c.insertAccount');
        var account = new Object();
        
        account.Name = component.get('v.accountName');
        account.NumberOfEmployees = component.get('v.accountNumOfEmployee');
       
        
        action.setParams({
            acc: JSON.stringify(account)
        });
        action.setCallback(this, function(response){
            let res = response.getReturnValue();
            alert(res);
        });
       // console.log(component.find('accName').get('v.value'));
        $A.enqueueAction(action);
	}
})

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Suraj Tripathi
 
This was selected as the best answer
Anu Singh 40Anu Singh 40
Thank you Suraj for your help.