Skip to content

DTO_Base

Class · Group: Data Transfer Objects

apex
@JsonAccess(serializable='always' deserializable='always') global inherited sharing virtual class DTO_Base

Known Derived Types: DTO_BaseTable, DTO_JsonBase, DTO_NameValues, DTO_ScheduledParameterDefinition

A base Data Transfer Object (DTO) class for storing JSON content, providing utility methods for serialization, deserialization, and transformation of DTOs. Supports pretty-print formatting for JSON content.

Example

apex
DTO_Base dto = new DTO_Base();
String json = dto.serialize();
dto.populate(recordId, new DTO_NameValues());

Methods

MethodDescription
global virtual DTO_Base deserialize(String dtoString)Deserializes a JSON string and populates a new instance of DTO_Base with the deserialized data, enabling conversion from JSON format back into a DTO.
global virtual void populate(Id recordId)Populates the current DTO instance using the specified triggering object ID.
global virtual void populate(Id recordId, DTO_NameValues dtoRequestParameters)Populates the current DTO instance using the specified triggering object ID and additional request parameters.
global virtual String serialize()Serializes the current DTO object to a JSON string.
global virtual void transform(DTO_Base dtoBase)Transforms the current DTO using another DTO as input.

deserialize

apex
global virtual DTO_Base deserialize(String dtoString)

Deserializes a JSON string and populates a new instance of DTO_Base with the deserialized data, enabling conversion from JSON format back into a DTO.

Parameters

ParameterTypeDescription
dtoStringStringA JSON-formatted string that can be converted to a DTO.

Returns DTO_Base — A DTO_Base instance populated with data from the provided JSON string.

Example

apex
DTO_Base result = instance.deserialize('value');

populate

apex
global virtual void populate(Id recordId)

Populates the current DTO instance using the specified triggering object ID. This method enables retrieval of relevant data using an ID parameter.

Parameters

ParameterTypeDescription
recordIdIdThe ID of the object to retrieve data for population.

Example

apex
instance.populate(recordId);
apex
global virtual void populate(Id recordId, DTO_NameValues dtoRequestParameters)

Populates the current DTO instance using the specified triggering object ID and additional request parameters. Allows customized data retrieval and population.

Parameters

ParameterTypeDescription
recordIdIdThe ID of the object to retrieve data for population.
dtoRequestParametersDTO_NameValuesA list of name values that can be used to change the query or the population of the request DTO

Example

apex
instance.populate(recordId, new DTO_NameValues());

serialize

apex
global virtual String serialize()

Serializes the current DTO object to a JSON string. This method provides a string representation of the DTO for storage or transfer.

Returns String — A serialized JSON string representing the DTO.

Example

apex
String result = instance.serialize();

transform

apex
global virtual void transform(DTO_Base dtoBase)

Transforms the current DTO using another DTO as input. This method allows flexibility for child classes to implement their own transformation logic.

Parameters

ParameterTypeDescription
dtoBaseDTO_BaseThe input DTO to transform from.

Example

apex
instance.transform(new DTO_Base());