See: Description
Interface | Description |
---|---|
DeleteRecordsResponse | Deprecated
as of 17R2.2, see
RecordService.deleteRecords(List) |
ObjectField |
Provides methods to retrieve common metadata information of the specified object field.
|
ObjectFieldCollectionRequest |
Retrieves a List of all fields in the
ObjectField once a request is built for the given object. |
ObjectFieldCollectionRequest.Builder |
Creates an instance of
ObjectFieldCollectionRequest . |
ObjectFieldCollectionResponse |
Holds a
ObjectField collection. |
ObjectFieldFilter |
Provides methods to retrieve required, unique, all, or a specific subset of object fields.
|
ObjectFieldFilter.Builder |
Creates an instance of
ObjectFieldFilter . |
ObjectFieldRequest |
Retrieves an instance of
ObjectField to build the request for retrieving object field metadata. |
ObjectFieldRequest.Builder |
Creates an instance of
ObjectFieldRequest . |
ObjectMetadata |
Provides methods to retrieve common metadata information of the specified object.
|
ObjectMetadataRequest |
Retrieves an instance of
ObjectMetadata to build the request for retrieving object metadata. |
ObjectMetadataRequest.Builder |
Creates an instance of
ObjectMetadataRequest . |
ObjectMetadataService |
Provides methods to retrieve object and object-field metadata.
|
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();
ObjectMetadataService
.
Then pass in the request objects to retrieve either the ObjectMetadata
or the
ObjectField
metadata.
Once the the metadata object is obtained, retrieve the desired metadata attributes, such as name or label.
The following example retrieves metadata of the country__v
object, including the label and active status:
// Initialize service
ObjectMetadataService objectMetadataService = ServiceLocator.locate(ObjectMetadataService.class);
// Build the request object for retrieving the country__v object metadata
ObjectMetadataRequest objectMetadataRequest = objectMetadataService.newObjectRequestBuilder()
.withObjectName("country__v")
.build();
// Retrieve country__v object metadata
ObjectMetadata countryMetadata = objectMetadataService.getObject(objectMetadataRequest);
// Retrieve the label and status of the country__v object
String countryLabel = countryMetadata.getLabel();
boolean isCountryActive = countryMetadata.isActive();
The following example uses an optional ObjectFieldFilter
to retrieve all
required fields of the country__v
object and then stores the names in a List:
// Initialize service
ObjectMetadataService objectMetadataService = ServiceLocator.locate(ObjectMetadataService.class);
// Get the builder for building the request object of ObjectFieldCollectionResponse
ObjectFieldCollectionRequest.Builder fieldCollectionRequestBuilder = objectMetadataService.newFieldCollectionRequestBuilder();
// Build the filter to only get required fields
ObjectFieldFilter onlyRequiredFieldsFilter = fieldCollectionRequestBuilder.newFieldFilterBuilder().withRequired(true).build();
ObjectFieldCollectionRequest objectFieldCollectionRequest = fieldCollectionRequestBuilder
.withObjectName("country__v")
.withFieldFilter(onlyRequiredFieldsFilter)
.build();
ObjectFieldCollectionResponse requiredCountryFields = objectMetadataService.getFields(objectFieldCollectionRequest);
// Store all the names of the required fields in a List
List<String> requiredFieldNames = VaultCollections.newList();
requiredCountryFields.streamFields().forEach(requiredField -> requiredFieldNames.add(requiredField.getName()));
If a specific subset of fields is required, use one or more of the filters in
ObjectFieldFilter
.
The following example uses the withUnique()
and withRequired()
filters to retrieves all unique,
non-required fields:
ObjectFieldFilter onlyUniqueAndNotRequired = fieldCollectionRequestBuilder.newFieldFilterBuilder().withUnique(true).withRequired(false).build();
Copyright © Veeva Systems 2017–2020. All rights reserved.