The below code is convenient to get list of fields come from different object.
For example we have taken a String, which contains Objects Api name like that ObjA__c, ObjB__c, ObjC__c and Fields Api name like that Status__c, Date__c, Description__c.
// Variable Declaration
String allstr = ‘ ObjA__c.Status__c,ObjB__c.Date__c,ObjC__c.Description__c’;
List<String> liststr=new List<String>();
//For Loop Start
for(String str : allstr.split(‘\\,’)){
String[] fieldnames = str.Split(‘\\.’);
system.debug(‘Field Only’+fieldnames[1]);
liststr.add(fieldnames[1]);
}
//For Loop End
system.debug(‘List Values’+liststr);
———————- Thank You ———————————-