Value provided is invalid for action parameter ‘fieldName’ of type ‘Date

You are currently viewing Value provided is invalid for action parameter ‘fieldName’ of type ‘Date
How to pass value to date parameter in apex method from LWC JS?

What you will learn:

  • how to resolve : Value provided is invalid for action parameter ‘fieldName’ of type ‘Date’ in LWC call to Apex
  • getting error : Value provided is invalid for action parameter ‘dateOfBirth’ of type ‘Date while creating record in apex
  • How to pass value to date parameter in apex method from LWC JS?

Error in console

Value provided is invalid for action parameter 'dateOfBirth' of type 'Date

We were getting “value provided is invalid for action parameter ‘dateOfBirth’ of type ‘Date” this error when we are trying to pass date type of value from lighting component to the apex method where apex is used to performing some data modification operations.

How to resolve ??

				
					// Make sure you pass null if date value not provided

dateOfBirth = ''; // error
dateOfBirth; // error

dateOfBirth = null; // correct

				
			

Apex method with Date parameter

				
					@AuraEnabled(cacheable = true)
    private void doSomethingOnDate(Date date) {
        // performing DML on date
    }
				
			

LWC to apex call

				
					dateOfBirth = new Date();
    onSaveRecord() { 
        doSomethingOnDate({ date: this.dateOfBirth })
        .then((data) => {
            // your code
        })
        .catch((error) => { 
            // return error
        });
    }
				
			

Leave a Reply