Can any one suggest me how I can get related objects and their fields of a parent object.Here is the code I have tried so far:
public void discoverRelatedAccessibleFields(sObject newObj) {
this.accessibleRelatedFields = new List<String>();
Map<String, Schema.SobjectField> fields =
newObj.getSObjectType().getDescribe().fields.getMap();
System.debug(fields);
for (String s : fields.keySet()) {
System.debug(s);
if ((s != 'Name') && (fields.get(s).getDescribe().isAccessible())) {
this.accessibleRelatedFields.add(s);
}
}
}
public Map<String,String> getRelatedObjects(String masterObjectName){
System.debug(masterObjectName);
Map<String,String> relatedObjectsMap = new Map<String,string>();
List<Schema.Childrelationship> relatedObjectsList = Schema.getGlobalDescribe().get(masterObjectName).getdescribe().getChildRelationships();
for (Schema.Childrelationship relatedObject : relatedObjectsList) {
if(relatedObject.getChildSObject().getDescribe().isUpdateable()
&&
relatedObject.getChildSObject().getDescribe().getKeyPrefix()!=null
&&
relatedObject.getChildSObject().getDescribe().isCreateable()
)
{
System.debug('***********');
relatedObjectsMap.put(relatedObject.getChildSObject().getDescribe().getName(),relatedObject.getChildSObject().getDescribe().getLabel());
String qid = ApexPages.currentPage().getParameters().get('id');
System.debug(qid);
for (String s : relatedObjectsMap.keyset())
{
string strName1 = relatedObjectsMap.get(s);
System.debug(strName1);
discoverRelatedAccessibleFields(strName1);
String theQuery = 'SELECT ' + joinList(accessibleRelatedFields, ', ') +
' FROM ' + strName1+
' WHERE Id = :qid';
System.debug(theQuery);
}
//return(Database.query(theQuery));
}
}
System.debug(relatedObjectsMap);
return relatedObjectsMap;
}
@strName1-getting related object name and getting compile error
"Method does not exist or incorrect signature: void discoverRelatedAccessibleFields(String) from the type DynamicObjectHandler".
Please help me with this