You need to sign in to do that
Don't have an account?
Abby Stocker
Required field via apex
Hello!
There is code (that I did not originally write) that I have been digging through to try to find out how to make a field required. What this code is doing: On a case, the user can select an option to "Tag Images". This will take them to a component and they can fill out specified fields. After the select "Submit", this will create a Case File record and it will be linked to the case. On the component screen, there are about 6 fields. Two of them need to be required to move forward. One is currently required and I will provide screenshots below.
They select a photo to tag:
They then get taken to a screen to fill out information about the image(s). Primary Reason (Return_Reason__c) and Secondary Reason (Return_Reason_Secondary__c) need to be required just like Order Line (Order_Line__c) is. I was able to add the asterisks in the code but I cannot get it to error on null. Here is the screen:
When you leave Order Line blank, here is the error:
I need this to happen when Primary Reason and Secondary Reason are left blank as well. After looking through all of the code, I found the component screen and added the highlighted text to show the asterisks on the two fields:
The only other thing I could find was in the Helper, I believe this is where the error message comes from for the Null Order Line:
But what I cannot find is the middle piece here. Where would it state in the code that IF Order Line is null - Display this error? Full Component in comments.
Thank you very much!!!!
There is code (that I did not originally write) that I have been digging through to try to find out how to make a field required. What this code is doing: On a case, the user can select an option to "Tag Images". This will take them to a component and they can fill out specified fields. After the select "Submit", this will create a Case File record and it will be linked to the case. On the component screen, there are about 6 fields. Two of them need to be required to move forward. One is currently required and I will provide screenshots below.
They select a photo to tag:
They then get taken to a screen to fill out information about the image(s). Primary Reason (Return_Reason__c) and Secondary Reason (Return_Reason_Secondary__c) need to be required just like Order Line (Order_Line__c) is. I was able to add the asterisks in the code but I cannot get it to error on null. Here is the screen:
When you leave Order Line blank, here is the error:
I need this to happen when Primary Reason and Secondary Reason are left blank as well. After looking through all of the code, I found the component screen and added the highlighted text to show the asterisks on the two fields:
The only other thing I could find was in the Helper, I believe this is where the error message comes from for the Null Order Line:
} else if(state === "ERROR"){ var errors = action.getError(); if (errors) { if (errors[0] && errors[0].message) { //alert(errors[0].message); var toastEvent = $A.get("e.force:showToast"); toastEvent.setParams({ title : 'Error', message:'There is an error '+errors[0].message+'', mode: 'sticky', key: 'info_alt', type: 'error' }); toastEvent.fire();
But what I cannot find is the middle piece here. Where would it state in the code that IF Order Line is null - Display this error? Full Component in comments.
Thank you very much!!!!
You can add the below if condition check for these two fields validations in saveFiles method:
I don't know how orderline field validation is working but it's looks like the error is thrown from apex class. So I have added orderline null check also in below if logic.
Thanks,
Maharajan.C
All Answers
You can add the below if condition check for these two fields validations in saveFiles method:
I don't know how orderline field validation is working but it's looks like the error is thrown from apex class. So I have added orderline null check also in below if logic.
Thanks,
Maharajan.C