DTO_Base
Class · Group: Data Transfer Objects
Learn it: DTOs guide
@JsonAccess(serializable='always' deserializable='always') global inherited sharing virtual class DTO_BaseKnown Derived Types: DTO_BaseTable, DTO_JsonBase, DTO_NameValues, DTO_ScheduledParameterDefinition
An empty base class for Data Transfer Objects (DTOs). A DTO is a small class that holds the fields you move in or out of your org. This class only declares the methods; on their own they do nothing: serialize() returns an empty string, deserialize() returns the same instance, and populate() and transform() change nothing. Your subclass overrides the methods it needs. For DTOs that convert to and from JSON, extend DTO_JsonBase instead.
Example
public class DTO_AccountSummary extends DTO_Base
{
public String accountName;
public override void populate(Id recordId)
{
accountName = 'Name read for ' + recordId;
}
}
DTO_AccountSummary summary = new DTO_AccountSummary();
summary.populate(recordId, new DTO_NameValues());Methods
| Method | Description |
|---|---|
| global virtual DTO_Base deserialize(String dtoString) | Turns a string 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() | Returns the DTO as a string. |
| global virtual void transform(DTO_Base dtoBase) | Transforms the current DTO using another DTO as input. |
deserialize
global virtual DTO_Base deserialize(String dtoString)Turns a string back into a DTO. In this base class it ignores the string and returns the same instance; override it in your subclass, or extend DTO_JsonBase, to read JSON.
Parameters
| Parameter | Type | Description |
|---|---|---|
dtoString | String | The string to read. This base class does not read it. |
Returns DTO_Base — The same instance, unchanged, in this base class.
Example
DTO_Base result = instance.deserialize('value');populate
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
| Parameter | Type | Description |
|---|---|---|
recordId | Id | The ID of the object to retrieve data for population. |
Example
instance.populate(recordId);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
| Parameter | Type | Description |
|---|---|---|
recordId | Id | The ID of the object to retrieve data for population. |
dtoRequestParameters | DTO_NameValues | A list of name values that can be used to change the query or the population of the request DTO |
Example
instance.populate(recordId, new DTO_NameValues());serialize
global virtual String serialize()Returns the DTO as a string. In this base class it returns an empty string; override it in your subclass, or extend DTO_JsonBase, to get JSON.
Returns String — An empty string in this base class.
Example
String result = instance.serialize();transform
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
| Parameter | Type | Description |
|---|---|---|
dtoBase | DTO_Base | The input DTO to transform from. |
Example
instance.transform(new DTO_Base());