Provide a mechanism to exclude object variables/properties from toString() - Ideas - Salesforce Trailblazer Community
Trailblazer Community

All Ideas

Idea Details

Post an Idea
30  Points
Idea has been posted. Give it an upvote or downvote.

Provide a mechanism to exclude object variables/properties from toString()

Development (Apex, LWC & VF)

If you use the transient keyword on a classes variables and then serialize an instance of the class to JSON the variable will be excluded.

Can we get a similar mechanism for Object.toString() ? (Without having to override toString on every Apex class)

E.g. Try the following anonymous Apex:

class WatchTheSize {
    public string largeString = 'Lorem Ipsum....';
    public transient string secretLargeString = 'dolor sit amet';

WatchTheSize wts = new WatchTheSize();
The first debug statement will output both strings. The JSON serialization will omit the transient variable.
15:16:13.2 (4687775)|USER_DEBUG|[7]|DEBUG|WatchTheSize:[largeString=Lorem Ipsum...., secretLargeString=dolor sit amet]
15:16:13.2 (9995886)|USER_DEBUG|[8]|DEBUG|{"largeString":"Lorem Ipsum...."}
This would be useful as an additional mechanism to protect sensitive data and to reduce the size of debug logs where entire objects are inadvertedly debugged out. It also has applications for wsdl2apex to reduce the size of CALLOUT_REQUEST logging.


Merge Idea · Flag

  • Upvotes
  • Downvotes



from AppExchange


No results found.

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.