Open Documentation Menu

Using the “DocumentSearchOptions.Builder” class

The dvelop_docs_dev.DocumentSearchOptions.Builder class makes it easier to create search parameters by implementing chainable methods.

Contents
Basics

The builder design pattern is a software engineering model that is frequently used to create complex data types using simple, compact commands and methods. The builder lets you concatenate method calls to create your product (that is, an instance of the complex data type) in a single statement, among other things.

The DocumentSearchOptions.Builder class implements the builder design pattern. You can create the class using the superclass buildOptions() method. This builder can configure a DocumentSearchOptions instance using any number of chainable methods.

You then obtain the result (“product”) of the builder through a call of getResult()

Example

To create a DocumentSearchOptions instance using the builder, follow the example below:

dvelop_docs_dev.DocumentSearchOptions searchOptions =
    dvelop_docs_dev.DocumentSearchOptions.buildOptions()    // Create an instance of the builder
    .withRecordContext('001AP000003aVJhYAM')                // Configure options - here: record context
    ...                                                     // Configure further options if necessary
    .getResult();                                           // Get the result - A completely configured instance of dvelop_docs_dev.DocumentSearchOptions
Methods

The DocumentSearchOptions.Builder class provides the following methods as corresponding counterparts to base class methods:

Method (builder)

Method(s) (base class)

withRecordContext(recordId)

useRecordContext(recordId)

withObjectContext(objectApiName)

useObjectContext(objectApiName)

withObjectContext(objectApiName, recordTypeId)

useObjectContext(objectApiName, recordTypeId)

withSearchAttribute(attributeKey, value)

addSearchAttribute(attributeKey, value)

withSearchAttribute(attributeKey, values)

addSearchAttribute(attributeKey, values)

withoutSearchAttributes()

ignoreSearchAttributes()

withSearchCategory(categoryKey)

addSearchCategory(categoryKey)

withSearchCategories(categoryKeys)

addSearchCategories(categoryKeys)

withoutSearchCategories()

ignoreSearchCategories()

withFolders()

showFolders()

withoutFolders()

hideFolders()

sortedAscendingBy(sortAttribute)

sortByAttribute(attributeKey)

sortAscending()

sortedDescendingBy(sortAttribute)

sortByAttribute(attributeKey)

sortDescending()

withSearchText(searchText)

setSearchText(searchText)

withMaxAgeInDays(maxAgeInDays)

setMaxAgeInDays(maxAgeInDays)

withPageIndex(pageIndex)

setPageIndex(pageIndex)

withPageSize(pageSize)

setPageSize(pageSize)

Use

You can find out how to use the builder to implement the application scenarios from DocumentSearchOptions > Use here.

Identifying all the documents for a data record (with global settings) 

dvelop_docs_dev.DocumentSearchOptions searchOptions =
    dvelop_docs_dev.DocumentSearchOptions.buildOptions()
    .withRecordContext('001AP000003aVJhYAM')
    .getResult();

Identifying all the documents for accounts (without global settings) 

dvelop_docs_dev.DocumentSearchOptions searchOptions =
    dvelop_docs_dev.DocumentSearchOptions.buildOptions()
    .withObjectContext('Account')
    .withoutSearchAttributes()
    .withoutSearchCategories()
    .getResult();

Identifying all the documents for accounts with a matching “accountnumber” property, “Schriftverkehr Kunde” (customer correspondence) or “Unbestimmte Dokumentart” (unspecified document type) document type, without folders 

dvelop_docs_dev.DocumentSearchOptions searchOptions =
    dvelop_docs_dev.DocumentSearchOptions.buildOptions()
    .withObjectContext('Account')
    .withSearchAttribute('accountnumber', '001AP000003aVJhYAM')
    .withSearchCategory('Schriftverkehr_Kunde')
    .withSearchCategory('Unbestimmte_Dokumentart')
	.withoutFolders()
    .getResult();

Complex use case 

dvelop_docs_dev.DocumentSearchOptions searchOptions = dvelop_docs_dev.DocumentSearchOptions
	.buildOptions()
	.withRecordContext('001AP000003aVJhYAM')
	.withSearchCategories(new List{ 'Schriftverkehr_Kunde', 'Eingangsrechnung', 'Unbestimmte_Dokumentart' })
	.withSearchAttribute('accountnumber', '001AP000003aVJhYAM')
	.withSearchAttribute('objecttitle', 'Testaccount')
	.withSearchAttribute('published', 'Ja')
	.sortedAscendingBy('createddate')
	.withSearchText('Produkt')
	.withMaxAgeInDays(1)
	.withPageIndex(1)
	.withPageSize(500)
	.getResult();