Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

This class of the Apex API allows you to find Dimension records that are available for a certain Reservation.


Methods
findAvailableDimensionIds(context)

Declaration

global static Set<Id> findAvailableDimensionIds(B25.AvailableDimensionIds.Context context)

Parameters

  • context (B25.AvailableDimensionIds.Context) 

Returns

  • Set<Id> The dimension IDs that would not result in any conflicts, if used for the given Reservation and Dimension Field.

Inner Classes
Context

Properties

  • reservation (B25__Reservation__c) - Reservation you want to insert.
    • B25__StartLocal__c and B25__EndLocal__c need to be set.
    • Make sure that any fields that influence conflict checking are set (i.e. the quantity of the reservation, or B25__Status__r.B25__AllowDoubleBooking__c if your Dimension Field is configured to skip conflict checking when this field equals true), or the result might not contain all available dimensions.
  • dimensionFieldName (String) - Name of the dimension field you want to search an available ID for. I.e. 'B25__Resource__c'.
  • dimensionIds (Set<Id>) - Scope of dimension IDs to limit the search to. These have to be of the same type as the dimension field that you are searching in.

  • excludedReservationIds (Set<Id>) - Reservation ids to ignore in conflict checking. This allows you to exclude reservations you are in the process of moving.

    dimensionIds

    The dimensionIds property narrows down the search scope. This greatly improves performance for dimensions with many records. It is recommended to fill this parameter when searching in dimensions with a large amount of records.

Example

The following example shows how you could implement the class to have it available in a Lightning Flow:

public class DimensionSelector {

    @InvocableMethod(label='Get Dimensions' description='Returns available Dimension IDs' category='Scheduling')
    public static List<DimensionResult> getDimensions(List<DimensionSelector.DimensionRequest> requests) {      
        Set<Id> scopeIds = (new Map<Id,SObject>([select id from B25__Resource__c where B25__Resource_Type__r.Name = 'Personal Stylist'])).keySet();
        List<DimensionResult> allResults = new List<DimensionResult>();
        for (DimensionRequest request : requests) {
            allResults.add(DimensionSelector.getResultForRequest(request, scopeIds));
        }
        return allResults;
    }
   
    private static DimensionResult getResultForRequest(DimensionRequest request, Set<Id> scopeIds) {
        DimensionResult result = new DimensionResult();
        B25.AvailableDimensionIds.Context context = createContext(request.getReservation(), request.dimensionFieldName, scopeIds);
        result.dimensionIds = new List<Id>(B25.AvailableDimensionIds.findAvailableDimensionIds(context));
        return result;
    }

    public class DimensionResult {
        @InvocableVariable(Label='Available Dimension IDs')
        public List<Id> dimensionIds;
    }

    public class DimensionRequest {
        @InvocableVariable(Label='Start' Required=true)
        public Datetime startDateTime;
        @InvocableVariable(Label='End' Required=true)
        public Datetime endDateTime;
        @InvocableVariable(Label='Dimension Field Name' Required=true)
        public String dimensionFieldName;

        public B25__Reservation__c getReservation() {
            return new B25__Reservation__c(B25__StartLocal__c = startDateTime, B25__EndLocal__c = endDateTime);
        }
    }

    public static B25.AvailableDimensionIds.Context createContext(B25__Reservation__c reservationIn, String dimensionFieldNameIn, Set<ID> dimensionIdsIn) {
        B25.AvailableDimensionIds.Context context = new B25.AvailableDimensionIds.Context();
        context.reservation = reservationIn;
        context.dimensionFieldName = dimensionFieldNameIn;
        context.dimensionIds = dimensionIdsIn;
        return context;
    }

}


Related articles

On this page

  • No labels