See: Description
Interface | Description |
---|---|
DeleteRecordsResponse | Deprecated
as of 17R2.2, see
RecordService.deleteRecords(List) |
PositionalRecordId |
Represents a successful result of processing a record in a batch operation.
|
ReadRecordsResponse |
Response from a call to
RecordService.readRecords(List) . |
Record |
Represents a Vault object record.
|
RecordBatchOperation |
Batch Operation to perform on records.
|
RecordChange |
Represents a Record that is being modified.
|
RecordService |
Provides methods to create, read, update, and delete Records.
|
RecordTrigger |
Invoked to start a trigger; takes
RecordTriggerContext as input. |
RecordTriggerContext |
Input to a
RecordTrigger . |
SaveRecordsResponse | Deprecated
as of 17R2.2, see
RecordService.saveRecords(List) |
Enum | Description |
---|---|
RecordEvent |
Contains valid Event values to specify when the trigger occurs.
|
Annotation Type | Description |
---|---|
RecordTriggerInfo |
Indicates a class is a
RecordTrigger . |
A record trigger is a Java class that implements the RecordTrigger
interface and has the RecordTriggerInfo
annotation as shown below:
@RecordTriggerInfo(object = "product__v", events = RecordEvent.BEFORE_INSERT)
public class ProductFieldDefaults implements RecordTrigger {
public void execute(RecordTriggerContext recordTriggerContext) {
for (RecordChange inputRecord : recordTriggerContext.getRecordChanges()) {
// Default Expected Date a week ahead
inputRecord.getNew().setValue("expected_date__c", LocalDate.now().plusWeeks(1));
}
}
}
The sample code above demonstrates how to manipulate current records by setting the expected_date__c
field to a week ahead. The annotation declares that the record trigger executes before a new product__v
record is inserted.
In addition to working with the current record, custom logic in a trigger can also use
RecordServce
to manage other records, such as creating related
child records. In the example below, we have an AFTER
trigger on the Product object that creates
a Product Brand record, which is a child of Product. We then update the parent field to the
Product's ID.
RecordService recordService = ServiceLocator.locate(RecordService.class);
Record record = recordService.newRecord("product_brand__c");
record.setValue("name__v", "Cholecap");
record.setValue("product__c", productId);
List<Record> records = VaultCollections.asList(record);
recordService.batchSaveRecords(records)
.onErrors(batchOperationErrors ->{
batchOperationErrors.stream().findFirst().ifPresent(error -> {
String errMsg = error.getError().getMessage();
int errPosition = error.getInputPosition();
String name = records.get(errPosition).getValue("name__v", ValueType.STRING);
throw new RollbackException("OPERATION_NOT_ALLOWED", "Unable to create: " + name +
"because of " + errMsg);
});
})
.execute();
Copyright © Veeva Systems 2017–2019. All rights reserved.