I have a list of field api names of type string belong to particular object. I want to validate whether the field has value or not at the time of saving the record and throw error message exactly at the field location if the value is not present for the field.
Integer count=0;
Map<String, Schema.SObjectField> M =Schema.SObjectType.Account.fields.getMap();
String fieldApiName;
for(String s : psProductFields)
{
fieldApiName = s;
if(AccountObj.get(s)==null || AccountObj.get(s)=='')
{
AccountObj.fieldApiname.addError('please provide the value');
count++;
}
}