I am trying to pass two Sobject names to a method and match using Schema the Field API Names common in both of them.
Like I have Object1 having fields A__c, B__c,X__c. Object2 having fields A__c, B__c,Y__c.
Here A__c and B__c are the matching fields. Now I need to put these field names in a Set which will have values 'A__c' , 'B__c'.
Can someone please help me to find out how to compare between two Schema.DescribefieldResult?
Apex code:
public static String Compare(String str, String str1)
{
String sObjectName = str;
String sObjectName1 = str1;
System.debug('========= '+ sObjectName);
List<Schema.SObjectField> sss=new list<Schema.SObjectField>();
if(sObjectName != null && sObjectName != '' )
Schema.SObjectType gd = Schema.getGlobalDescribe().get(sObjectName);
Schema.DescribeSobjectResult a11=gd.getDescribe();
Map<String, Schema.SObjectField> M = a11.fields.getMap();
for(Schema.SObjectField s1:m.values()){
Schema.DescribeFieldResult f = M.get(s1.getDescribe().getName()).getDescribe();
Schema.SObjectType gd1 = Schema.getGlobalDescribe().get(sObjectName1);
Schema.DescribeSobjectResult a=gd1.getDescribe();
Map<String, Schema.SObjectField> M1 = a.fields.getMap();
for(Schema.SObjectField s2:m1.values()){
Schema.DescribeFieldResult f2 = M2.get(s2.getDescribe().getName()).getDescribe();
}
}