1

I would like to know if there's a way to add the related list in the parent object after I've created a lookup field trough the metadata-api?

this is what I'm doing:

  1. Creating the field:
String relationshipObjectName = 'test'; 
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element(); 
service.SessionHeader.sessionId = UserInfo.getSessionId(); 
MetadataService.CustomField customField  = new MetadataService.CustomField(); 
customField.fullName = 'test'+;
customField.label= relationshipObjectName;
List results = service.createMetadata(new MetadataService.Metadata[] {customField}); 

result = handleSaveResults(results[0]);

After that I'm only updating the field level security with MetadataService.ProfileFieldLevelSecurity service..

1 Answer 1

1

You can add related lists, but you have to do this "manually." The UI handles this for you by automatically giving you a choice as part of the field creation wizard, but if you're going about this programmatically, you need to actually query the page layouts (see Layout), then add a new RelatedListItem to the relatedLists part of the layout object(s). The actual process depends on what you're writing this in (I'm guessing Java or Apex Code, but it's not clearly specified/tagged here), but should basically consist of querying the layouts, constructing a new RelatedListItem, populating the various elements needed, then deploying the changes.

You must log in to answer this question.

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