You need to sign in to do that
Don't have an account?
Dnyaneshwar Kakad
How to detect a required field in field set through Apex.
Is there any way to determine which field is required at fieldset level in Apex
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Check below references to detect a required field in field set through apex.
https://salesforce.stackexchange.com/questions/229684/how-to-detect-a-required-field-from-a-fieldset
https://sfdctrails.com/2021/10/04/how-to-identify-required-fields-of-object-using-apex/
Please mark as Best Answer if above information was helpful.
Thanks,
You can try the below code for checking the required field in field set through Apex
Schema.FieldSet myFieldSet = Schema.SObjectType.YourObjectname__c.fieldSets.YourFieldSetName;
Set<String> requiredFields = new Set<String>();
for (Schema.FieldSetMember fieldSetMember : myFieldSet.getFields()) {
String fieldName = fieldSetMember.getFieldPath();
Schema.DescribeFieldResult fieldDescribe = YourObjectname__c.SObjectType.getDescribe().fields.getMap().get(fieldName).getDescribe();
if (!fieldDescribe.isNillable() && fieldDescribe.isCreateable()) {
requiredFields.add(fieldName);
}
}
System.debug('Required Fields in Field Set: ' + requiredFields);
OR
You can check the below reference for more info
https://sfdctrails.com/2021/10/04/how-to-identify-required-fields-of-object-using-apex/
Mark this as best answer if this helps.
Thanks