Apex Aide apexaide

Formatted Output from Copilot Custom Actions

By Bob Buzzard· Bob Buzzard Blog· ·Intermediate ·Developer ·6 min read
Summary

Einstein Copilot's response formatting varies between plain text and styled outputs using Lightning Design System. This demonstrates how to return formatted results from Copilot custom actions using Apex, specifically by wrapping records in custom classes or wrappers to control appearance. It highlights practical Apex patterns to present sObject records alongside commentary with styled Lightning cards. Teams can leverage these insights to build clearer, visually consistent Copilot responses within the Salesforce UI despite limited documentation.

Takeaways
  • Return lists of custom class instances to enable better Copilot formatting.
  • Wrap sObject records in wrapper classes to combine data and commentary.
  • Leverage alphabetical property ordering to control displayed field order.
  • Text or HTML responses show as plain text; use custom objects for styling.
  • Copilot renders each property in its own box without record separation.

Image generated by DALL-E 3 based on a prompt from Bob Buzzard Introduction If you've seen any of the demos of Einstein Copilot, you'll notice that sometimes the responses are nicely formatted using the Lightning Design System, while other times they are simply text on a darker background - e.g. from the TrailblazerDX keynote, the pipeline information is text: While the contacts are shown as a formatted list, with fields specific to the solution: This isn't particularly well documented, so it's a matter of trial and error to figure out what works and what doesn't. Text Responses Text responses came out the same regardless of what I tried - the text that I return appears on a dark background. If I format it as JSON or CSV, it comes out in JSON or CSV format, even if I included instructions to display as a list of label/value pairs.  The same goes for HTML markup - it's taken as text and shown to the user.

Apex