1

Gurus, I'm creating a MasterDetail field in the child object with the following code:

    Schema.DescribeSObjectResult parentObj = Schema.getGlobalDescribe().get('account').getDescribe();
    MetadataService.CustomField bdpoField = new MetadataService.CustomField();
    bdpoField.fullName = 'Bank__c.Parent__c';
    bdpoField.externalId = false;
    bdpoField.label = parentObj.getLabel();
    bdpoField.referenceTo = parentObj.getName();
    bdpoField.relationshipLabel = parentObj.getLabel();
    bdpoField.relationshipName = 'BankParent';
    bdpoField.relationshipOrder = 0;
    bdpoField.type_x = 'MasterDetail';
    bdpoField.writeRequiresMasterRead = false;
    List<MetadataService.SaveResult> saveResults = service.createMetadata(
        new MetadataService.Metadata[] { bdpoField }
    );
    handleSaveResults(saveResults[0]);

But when I go to the parent object - in this case Account object-, I cannot find this child object in the related list options on Edit Layout. Anybody has been with the same trouble? How to solve this?

3
  • did you try comparing OOB SFDC OpportunityLineItem (a detail to Opportunity) looks like versus your custom M-D?
    – cropredy
    Jul 18, 2015 at 18:53
  • yeah it's look exactly the same type of object. the difference is that my Bank object has a Record Type Master. Jul 20, 2015 at 13:49
  • I'm searching more and more, and I think the RelatedList is an object and it's not created. But I can't find how to create a Related List via metadata api. Any ideas or am I wrong? Jul 20, 2015 at 14:50

1 Answer 1

0

my fault.

The "problem" was at this line: bdpoField.relationshipLabel = parentObj.getLabel();

The relationshipLabel as with the same name as the Parent object. And actually, that related list was there to drag'n'drop, but I never thought to use that.

Now it's okay, I changed this label to Banks and everything is fine.

I'm answering this here for the next guy with the same problem save hours/days with this issue.

Thank you and sorry for the mistake.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .