Sample Code:
Here in below code I’m getting all required fields of “Account” object.
Map<String, Schema.SObjectType> mapObj = Schema.getGlobalDescribe(); Schema.SObjectType sObjType = mapObj.get('Account'); Schema.DescribeSObjectResult objDescribe = sObjType.getDescribe(); Map<String,Schema.SObjectField> mapFields = objDescribe.fields.getMap(); List<String> requiredFieldList = new List<String>(); for(String obj : mapFields.keyset()) { Schema.DescribeFieldResult describeField = mapFields.get(obj).getDescribe(); if (describeField.isCreateable() && !describeField.isNillable() && !describeField.isDefaultedOnCreate()) { requiredFieldList.add(obj); System.debug(obj); } }