I want to create an overview of a list which contains content from different objects. I will try to add in this list the files, tasks, events, emails and notes. If I query for each object a list, how can I concatenate all these lists into one list. Is that possible because of different object and structure?
Yes, you can.
sObject can hold any type of database record, such as:
sObject results = new sObject; results.addAll([SELECT Title FROM ContentDocument]); results.addAll([SELECT Subject FROM Task]); results.addAll([SELECT Subject FROM Event]); results.addAll([SELECT Subject From EmailMessage]); results.addAll([SELECT Title FROM Note]);
If you decide you want to use a Data Transfer Object (DTO) model in your code, you can also decide to use a parent DTO object type, or even just
Object, which is the parent of all object types.
I am not sure I understand difference between DTO and a wrapper class. Can you please enlighten me. For example in author scenario I am thinking wrapper class would also suffice scenario.– ElijahJul 13, 2021 at 8:39
2@elijah A DTO (Data Transfer Object) is a subset of a wrapper. In other words, all DTO are wrappers, but not all wrappers are DTO, much like how all dogs are animals, but not all animals are dogs. You are correct that a wrapper class would be employed, it's just that a DTO usually has minimal functionality, designed only to transfer data between client and server, while a full wrapper class often has methods to aid manipulating the data somehow.– sfdcfoxJul 13, 2021 at 9:14
Sorry, one more questen. Can you tell me how can I display the results at a visualforce page?– peXeqJul 14, 2021 at 3:57
@peXeq You may want to ask a separate question for that. We would need much more detail than a comment is going to be able to provide.– sfdcfoxJul 14, 2021 at 4:03