We have a page that queries entities with certain criteria.

The way we implement it is by getting list of entity IDs, loop the IDs retrieve the entity model per ID and add it into the list.

Pseudo code:

Query query = new Query(...);
// Get list of ids from query
List<String> ids = Arrays.asList(query.executeQuery());

final WebComponentMetaFactory cmf = new WebComponentMetaFactoryImpl(brokerQuery.getPublicationId());

// Get component meta
List<ComponentMeta> componentMetas = ids.stream().map(cmf::getMeta)

// Get entity model per component and add it to the list
componentMetas.forEach(meta -> {
   EntityModel entityModel = contentProvider.getEntityModel(meta.getId() + templateId, webRequestContext.getLocalization())

This works, however from performance point of view is very slow because it needs to call contentProvider.getEntityModel(...) for every ID.

Is there a better solution for this? Perhaps an API from DXA that generates list of EntityModel?

  • which version of sites?
    – Velmurugan
    Oct 29, 2020 at 7:49
  • We use Tridion 8.5. I thought that won't matter much, because this is DXA framework related?
    – Chris
    Oct 29, 2020 at 9:24
  • I just asked if it's Sites 9.0+ graphql query it's possible to fetch the DCPs jsons using item query filter by a single call to fetch the items and also entity jsons data in the same response.
    – Velmurugan
    Oct 29, 2020 at 9:29
  • why you want this entity model list in a web application?
    – Velmurugan
    Oct 29, 2020 at 9:33
  • @Velmurugan With GraphQL, you could indeed retrieve DCPs with a single call. But I wonder, if we could retrieve with DXA in a similar way (so you't have to deserilaize json to strongly typed object). e.g. a method like 'contentprovider.getAllEntityModels(List of ID's). I havn't seen a method like this in DXA 2.2 (java) version. Oct 29, 2020 at 10:55

1 Answer 1


Use this below CIL API to Fetch multiple DCP content by a single call example provided below is based on .NET similar API also available in java.

string[] componentUris = query.ExecuteQuery();

var components = componentUris
                .Select(componentUri => { TcmUri uri = new TcmUri(componentUri); return (ComponentPresentation)new ComponentPresentationFactory(uri.PublicationId).FindAllComponentPresentations(componentUri)[0]; })
                .Where(cp => cp != null)
                .Select(cp => cp.Content)

I hope it helps.

  • Is that really a single call though? Aren't you just calling FindAllComponentPresentations() for each item in the componetUris array?
    – Neil
    May 25, 2021 at 13:18
  • @Velmurugan In one of the comments you mentioned graphql. Now we are trying to migrate to 9.5 site and wonder if you have sample code for graphql?
    – Chris
    Jun 22, 2021 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.