AqResult
The result of an operation. Can represent any exception or set of exceptions, as well as success, failures, or warning results. Intended to be fully serializable and structured to allow programmatic analysis.
Implemented types
Group apex/core
Constructors
public AqResult(String type, String severity, String level, String scopeType, String source, String scope, String code, String message, Object detail, Object returnValue, Datetime resultDate, List<AqResult> subResults)
Use AqResultBuilder to simplify AqResult creation
Usage Use AqResult as a response wrapper for your custom baseService.LightningElement LWC component. See lwc-core\main\lwc\networkService.js. Apex controller:
Example
@AuraEnabled
public static AqResult getTaskMetadata() {
try {
return new AqResultBuilder()
.setSeverity(AqResult.SEVERITY_SUCCESS)
.setReturnValue(new TaskMetadataModel())
.createAqResult();
} catch (Exception e) {
return AqResultBuilder.getBadResult(e.getMessage());
}
}
// LWC component (extending baseService.LightningElement):
// import getTaskMetadata from '@salesforce/apex/YourController.getTaskMetadata';
// connectedCallback() {
// this.sfData.get(getTaskMetadata)
// .then(response => {
// this.taskMeta = response;
// })
// .catch(error => {
// this.showToast(error);
// });
// }
Fields
Standard result types
public RESULT_TYPE_VALIDATION→Stringpublic RESULT_TYPE_SHIELDED→Stringpublic RESULT_TYPE_DML_ROW_DETAIL→Stringpublic RESULT_TYPE_SAVE→Stringpublic RESULT_TYPE_DELETE→Stringpublic RESULT_TYPE_UPSERT→Stringpublic RESULT_TYPE_EMAIL→Stringpublic RESULT_TYPE_EMAIL_ERROR→Stringpublic RESULT_TYPE_DATABASE_ERROR→String
Valid severities
public SEVERITY_SUCCESS→String- Successpublic SEVERITY_INFORMATION→String- Success with informationpublic SEVERITY_WARNING→String- Success with warningpublic SEVERITY_PARTIAL_ERROR→String- Some records succeeded and some failedpublic SEVERITY_ABORTED→String- Never tried due to other errorspublic SEVERITY_ROLLED_BACK→String- Would have succeeded but rolled back due to other errorspublic SEVERITY_ERROR→String- Failurepublic SEVERITIES_ALL→Set<String>public SEVERITIES_ERROR→Set<String>public SEVERITIES_ORDER→Map<String,Integer>
Valid levels
public LEVEL_USER→String- Result relates directly to user actions -- end user can see detailspublic LEVEL_BUSINESS→String- Result relates to business rules -- end user can see detailspublic LEVEL_INTERNAL→String- Internal -- details should be shielded from end userpublic LEVELS_ALL→Set<String>public LEVELS_SHIELD→Set<String>
Standard scope types
public SCOPE_TYPE_RECORD→String- Object recordpublic SCOPE_TYPE_FIELD→String- Object fieldpublic SCOPE_TYPE_EMAIL→String
Standard codes
public CODE_CREATED→Stringpublic CODE_UPDATED→Stringpublic CODE_DELETED→String
Other
public BUSINESS_STATUS_CODES→Set<StatusCode>- Database status codes that can be considered business level not internal
Properties
public Type → String
Type of result, usually an exception type
public Severity → String
AURAENABLED
Identifies severity of the result
public Level → String
Identifies the audience that should be able to see the error details
public ScopeType → String
Identifies the data being reported on. Could be object, field, record, etc. E.g. 'Field'
public Scope → String
E.g. 'DocumentName__c'
public Source → String
Identifies the source component/method.
public Code → String
AURAENABLED
Invariant identifier for the result (vs. Message which is localized and may change)
public Message → String
AURAENABLED
General message
public ResultDate → DateTime
Date/time of result
public Detail → Object
Object with additional detail, must be serializable
public ReturnValue → Object
AURAENABLED
For use with Lightning server actions or any other case where the result needs to return a value of the operation When used, the Type field should indicate the type of the value
public SubResults → List<AqResult>
AURAENABLED
Sub-results if relevant
Methods
public Boolean hasError()
Return true if has an error severity Does NOT include partial error
public Boolean severityAtLeast(String severity)
Returns true if severity is at or worse than specified severity
public override String toString()
Dump as text
public AqResult addSubResult(AqResult subResult)
Convenience for adding subresult only if not null
public AqResult addSubResultAndRollup(AqResult subResult)
Convenience for adding subresult only if not null
public void rollupSeverity()
Go through all subresults and apply worst severity to this result. This method is never called recursively, only looks at immediate child subresults.
public String rollupSeverity(Boolean allOrNone, String successSeverity)
Go through all subresults and apply worst severity to this result. This method is never called recursively, only looks at immediate child subresults.
public AqResult mergeResult(AqResult result)
Merge the specified result into the current one. Use when you need to apply the result of an operation to some existing ongoing result. Essentially merges sub-results together and discards the result being merged in.
public static Boolean hasError(AqResult results)
Returns whether any result in the list has an error. Results are allowed to be null.
public static AqResult shield(AqResult result)
Decide whether the result details should be shown to the user, and if not, log and make generic result.
public static AqResult shield(System e)
Shield directly from exception