Redux form set custom error message based on field's hinttext in Field Validation - reactjs

I am trying to write a Field validation so that i don't have to write separate validation in every file. While trying to do it, i am able to get value of the field as well as the whole form fields.
I have to set the error message based on the field name, eg.
For field name as Firstname the error message has to be : First name is invalid.
is there a way to implement this with the Field Validation, or the sync validation is the only way?
Any help will be appreciated.

There is a "hacky" way to do this. Since in field validation you get field value and form values as parameters, you could get field name (which would be the key of the form values object) by searching for a matching value in form values. Then you would need to have a file with field name translations where you could get the field name, e.g. translations[fieldName].
However, since the above way requires more setup and sync validation is relatively simple, I would recommend using sync validation.

Related

How to Update RecordTypeId field in Lightning record form in salesforce?

Hi #all I have lightning record edit form which are showing specific value one of them is a recordtype. I want to update the recordtype from the same as other fields are updating but when I click on recordtype field it shows me the below error:-
[LWC component's #wire target property or method threw an error during value provisioning. Original error:
[Field: RecordTypeId is not a valid lookup field.]]
Record Type change is a critical operation that messes everything up. Potentially you're looking at new page layout (incl required/readonly fields), new picklist dependencies... There's reason why you select it first before any layout is displayed. And why record type change is a special button, not a field visible on normal edit action.
If you know what you're doing, are confident the requirements won't change / you'll know how to represent the changed layouts, picklists etc...
Use getObjectInfo to pull (among others) the Map of record types.
Use this data to build lightning-combobox that onchange updates a helper variable (you'd ideally have that variable bound to <lightning-record-edit-form record-id={recordId} record-type-id={recordTypeId}
Have a custom handleSubmit in the record-edit-form in which you'd intercept the save, prepopulate the field and then submit.

Can I check react-final-form directly for whether or not it's displaying a validation error for a particular field?

We currently have rules encoded in json that determine if react-final-form will display a validation error or not which I believe is standard. So meta.error will have data for an invalid field and our error display component will display the error. It would be convenient to be able to query something directly to find out if an error message is being displayed for a particular field. Like if the field is called name then form.name.meta.error or state.name.meta.error. Is there anything like that in the api?

INVALID_FIELD_FOR_INSERT_UPDATE in Salesforce via API

I am trying to make a batch update to Salesforce as part of a data masking project and am getting the error INVALID_FIELD_FOR_INSERT_UPDATE when I try updating fields of a particular custom object via API.
Our custom object has a few standard fields and a few custom fields. The custom fields are what I'm trying to update but I keep getting denied.
Each field that I'm trying to update is either Long Text Area(32768) or Text(255). There are no lookups, controlling fields, validation rules, nor are there field dependencies.
I am able to make modifications to other objects (Account for example) via the masking process. I am also able to make modifications to the values through the web UI on the values for this custom object.
I've tried as members of the API group as well as System Administrator.
Can anyone please point me in the right direction? I don't have access to the source code of the masking tool, but I do have elevated rights in SF.
Thanks in advance for your advice.
The exact error:
INVALID_FIELD_FOR_INSERT_UPDATE Error message: Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.
The funny thing is that I'm not trying to update the field "Name". Name seems to be an auto-number field on the object, but I'm not sure why this field would change value on an update to a different column.
If some one facing the same issue of not able to update the Name column because it has data type as Name.
There are 2 solutions:
If you want to push the name of human then try pushing FirstName and LastName instead. "Name" will get populated automatically.
If you want to push the name of a product then try changing the type of Name field to Text. If that doesn't work then you can push the name to either FirstName or LastName, whichever is mandatory(Just A work around).

Show and hide server-side errors in AngularJS 1.3+ forms

I'm using the Angular framework with Angular Material controls in my recent application. I'm looking for a good solution for the following problem:
A form form with an input field named nickname is shown to the user. After the user has chosen a nickname and submitted the form, the server checks whether the nickname has already been taken. In that case, it returns an error to the Angular client.
To show an appropriate error to the user, the code then calls form.nickname.$setValidity('nicknameTaken', true). The new ngMessages module is used to display the error to the user. Further form.$isInvalid is used to disable the form controls to prevent the user from resubmitting the invalid nickname.
My problem is now the following: I'd like to have the error nicknameTaken automatically being removed as soon as the user begins to edit the form fields again. What is a good way to do this? Is there a predefined route to go when it comes to server-side validation errors of this kind? (Note that I am not asking for asynchronous validation because I only want to contact my server when the form is actually being submitted.)
I would write a normal validator directive instead. Something like
<input blacklist="takenNickNames" .../>
This directive would simply add a validator to the input, and this validator would make the input invalid if the model value is contained inside the given takenNickNames array (and valid if it's not present).
The takenNickNames array would be empty initially. When the form is submitted and the error comes back, the controller would add the invalid nick name to the array.
So, every time the user would enter something, the validator would be triggered, and would set the field valid or not, based on the taken nicknames stored in the array.
Here is a working example.

How do I get the SalesForce record id in a custom field

I wanted to add a simple read-only URL-field to 'opportunities' in SalesForce that contains a link to an external webpage with the 15-char record id (used in the salesforce urls) attached to it . To do this I wen to /ui/setup/Setup?setupid=Opportunity --> fields and created a new field under 'Opportunity Custom Fields & Relationships'.
I chose a field with data type 'URL' and added a default value. I thought
"http://example.com/?sfid="&id would do the trick, but this returns
Error: Field id may not be used in this type of formula
This is a vague error. Is my syntax of a default value wrong, or am i using the 'id' parameter in a wrong way? And what is the right way to do this?
I'm new to SalesForce, as you probably already have guessed.
As the other answer stated - Id will be known only after insert meaning the "default value" trick won't work for you.
You have some other options though:
Workflow rule that would be populating the URL field after save.
Formula field of type text that uses HYPERLINK function
HYPERLINK("http://example.com/?sfid=" & Id , "See " & Name & " in ext. system")
Custom link (similar to custom buttons, they appear on the bottom of the page layout. Search them in online help)
The difference between 2 and 3 is quite minor. Custom links can appear only on the record's detail view while formula fields & other urls are well... fields - so they can be used in reports, listviews etc.
You'd have to decide which version suits you best.
This is a great question. You're right, the error is very vague.
To begin with, read some of the documentation on default fields. Pay particular attention to the order of operations:
The user chooses to create a new record.
Default field value is executed.
Salesforce displays the edit page with the default field value pre-populated.
The user enters the fields for the new record.
The user saves the new record.
Default field values are calculated before any other record data including the id are available. For this reason, they cannot be calculated based on other record fields. Especially the record id, which has not yet been assigned.
To get this functionality, you will need to create a workflow rule that fires on record creation and inserts the proper value into your field.
It would be nice if we could have formula URL fields, but we don't. EDIT: I am dumb and forgot about using HYPERLINK in text formula fields, as eyescream correctly points out.

Resources