Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt
hiddentrue

Enables developers to validate series of reservations against

...

GoMeddo's conflict checking configuration.

The BulkReservationValidator enables developers to validate one or more series of Reservations. It will return all the soft and hard conflicts that would arise, given the current configuration. For more information on how to configure conflict checking, see this article.

Methods

...

Expand
titlevalidate

This method takes one or more lists of reservations wrapped in a Context class, and adds any detected soft or hard conflicts to them.

...

...

borderColorgrey
titleBGColorgrey
borderStylesolid

Signature

Code Block

...

...

global static B25.BulkReservationValidator.Result validate(B25.BulkReservationValidator.Context

...

)

Parameters

Code Block

...

B25.BulkReservationValidator.Context

An instance of B25.BulkReservationValidator.Context. This class wraps the series of reservations to be validated.

Return Type

Code Block

...

B25.BulkReservationValidator.Result

This is a dummy class without properties. This allows us to add properties later without changing the method signature. For now, developers can ignore the result, because the validation results are added to the individual B25.BulkReservationValidator.Reservation instances that were passed as the input.

Inner Classes

Expand
titleContext

...

This class wraps the series of reservations to be validated.

...

titledetails

...

...

Properties

Code Block

...

languagejava
List<List<B25.BulkReservationValidator.Reservation>> reservationSeries

This is a nested list of B25.BulkReservationValidator.Reservation instances, which are the wrappers around the reservations to be validated.

...

Info

Reservations in the same list will be conflict checked as if they would be inserted together, so if they overlap they could conflict with each other. Reservations in separate lists will not conflict with each other.

Expand
titleResult

This is a dummy class without properties. This allows us to add properties later without changing the method signature. For now, developers can ignore the result, because the detected are added to the individual B25.BulkReservationValidator.Reservation instances that were passed as the input.

Expand
titleReservation

This class wraps a B25__Reservation__c object, as well as related child objects of the reservation. It has two additional properties, softConflicts and hardConflicts, which will be set by the validate method.

...

titledetails

...

Properties

Code Block

...

B25__Reservation__c record

The record that you want to validate. Any related child records should be added to the childRecords property.

Code Block

...

Map<String, List<SObject>> childRecords

This map allows you to specify related child records that should also be validated, such as a list of ReservationContacts. Use the relationship name as the key (so 'B25__ReservationContacts__r' for example).

Code Block
List<B25__Conflict__c> softConflicts

This property will be set by the validate method. It will contain all the soft conflicts that would be generated if the Reservation would be saved to the database.

Code Block
List<B25__Conflict__c> hardConflicts

This property will be set by the validate method. It will contain all the hard conflicts that would be generated if the Reservation would be saved to the database.

Result Class

This is a dummy class without properties. This allows us to add properties later without changing the method signature. For now, developers can ignore the result, because the detected are added to the individual B25.BulkReservationValidator.Reservation instances that were passed as the input.

Example

...

Code Block
B25__Resource__c resource = [SELECT Id FROM B25__Resource__c WHERE Name = 'Resource One'];
B25__Staff__c staffMember = [SELECT Id FROM B25__Staff__c WHERE Name = 'Staff Member One'];

// first construct the context parameter
B25.BulkReservationValidator.Context context = new B25.BulkReservationValidator.Context();
context.reservationSeries = new List<List<B25.BulkReservationValidator.Reservation>>{
    new List<B25.BulkReservationValidator.Reservation>{
		new B25.BulkReservationValidator.Reservation(
			new B25__Reservation__c(
				B25__StartLocal__c = Datetime.newInstance(2020, 1, 1, 8, 0, 0),
				B25__EndLocal__c = Datetime.newInstance(2020, 1, 1, 10, 0, 0),
				B25__Resource__c = resource.Id,
				B25__Staff__c = staffMember.Id
			)
		),
		new B25.BulkReservationValidator.Reservation(
			new B25__Reservation__c(
				B25__StartLocal__c = Datetime.newInstance(2020, 2, 2, 14, 0, 0),
				B25__EndLocal__c = Datetime.newInstance(2020, 2, 2, 16, 0, 0),
				B25__Resource__c = resource.Id,
				B25__Staff__c = staffMember.Id
			)
		)
	}
};

// then call the method
B25.BulkReservationValidator.validate(context);

// the reservations in the context parameter now have soft and hard conflicts
for (B25.BulkReservationValidator.Reservation reservation : context.reservationSeries[0]) {
	System.debug('number of soft conflicts: ' + reservation.softConflicts.size());
	System.debug('number of hard conflicts: ' + reservation.hardConflicts.size());
}

...

Contents

...