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
Martina Dimitrieva 2Martina Dimitrieva 2 

lightning:recordEditForm with lightning:inputField

Hi,

I am getting following error while using lightning:recordEditForm with lightning:inputField,  "Value for field 'NumberOfEmployees' is not a number: 123". 
My code is this:
<aura:component implements="lightning:actionOverride,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" >


            <lightning:recordEditForm aura:id="edit" recordId="{!v.recordId}" objectApiName="Account"  >
                <div aura:id="msg">
                    <lightning:messages  />
                </div>
                     <lightning:inputField fieldName="Name" />
                       <lightning:inputField fieldName="Phone" />
                <lightning:inputField fieldName="NumberOfEmployees" />

                <footer class="slds-modal__footer">
                    <lightning:button variant="neutral" label="Cancel" onclick="{!c.cancelBtn}"/>
                    <lightning:button aura:id="submit" label="Save" variant="brand" type="submit"  />

                </footer>

            </lightning:recordEditForm>



    </aura:component>
Does anyone know how to fix it? 
Best Answer chosen by Martina Dimitrieva 2
Bozhidar TyanevBozhidar Tyanev

Hi,

Currently, all "int" fields will throw an error if you give them a value while using lightning:recordEditForm. I was able to come with a workaround:

Make a handler to onsubmit event of the form. This event is fired before dispatching the submit request.
 

<lightning:recordEditForm aura:id="create" objectApiName="Account" recordId="{!v.recordId}" onsubmit="{!c.onSubmit}">

You have access to all collected fields and values there which are to be submitted so you would find that field and cast it to an integer.

// Intercept the submit event
    onSubmit  : function(component, event, helper) {
        // get all fields from the form. Note that the Form have already gathered and parsed the fields
        // so we need to fix the wrongfully parsed values
        var eventFields = event.getParam("fields");
        var field = 'NumberOfEmployees';
        
        // check if the field exists
        if (eventFields.hasOwnProperty(field)) {
            // we know this should be Integer but instead its a String, so we parse it
            eventFields[field] = parseInt(eventFields.NumberOfEmployees);
            // assign the fields back to the event
            event.setParam("fields", eventFields);
        }
    },
This will result in a successful save.

Regards
 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

I would suggest you check for NumberOfEmployees field if it was created as number type or text type.

Best Regrads
Martina Dimitrieva 2Martina Dimitrieva 2
Hi,

NumberOfEmployees is a standard Salesforce field with type number. If you open the Account object in the developer console, the apexType for this field is int.

Regards
Bozhidar TyanevBozhidar Tyanev

Hi,

Currently, all "int" fields will throw an error if you give them a value while using lightning:recordEditForm. I was able to come with a workaround:

Make a handler to onsubmit event of the form. This event is fired before dispatching the submit request.
 

<lightning:recordEditForm aura:id="create" objectApiName="Account" recordId="{!v.recordId}" onsubmit="{!c.onSubmit}">

You have access to all collected fields and values there which are to be submitted so you would find that field and cast it to an integer.

// Intercept the submit event
    onSubmit  : function(component, event, helper) {
        // get all fields from the form. Note that the Form have already gathered and parsed the fields
        // so we need to fix the wrongfully parsed values
        var eventFields = event.getParam("fields");
        var field = 'NumberOfEmployees';
        
        // check if the field exists
        if (eventFields.hasOwnProperty(field)) {
            // we know this should be Integer but instead its a String, so we parse it
            eventFields[field] = parseInt(eventFields.NumberOfEmployees);
            // assign the fields back to the event
            event.setParam("fields", eventFields);
        }
    },
This will result in a successful save.

Regards
 
This was selected as the best answer
Lena ReeseLena Reese
Thanks, this is the right solution 
short life (https://shortlife.co) online