Working with FormRecords

Use fieldsets to query fields on existing records

B25.FormRecords (such as returned by B25.Form.getActiveRecord or B25.FormRecordCollection.get, for example) for existing records get their fields populated by GoMeddo queries before your CFL is executed. GoMeddo populates all the fields contained in any fieldset on the target object. This means that if your CFL implementation references fields that are not present on the form, you can let GoMeddo populate them by adding any fieldset containing those fields.

For example, your form displays Service Reservations, and your CFL has a handler that uses a checkbox on Service Reservations to decide what to do with them, but you do not want to display this checkbox on the form. When you test your CFL on an existing Reservation with existing Service Reservations, it fails because the checkbox has not been populated and always contains null. One option available to you is to modify your CFL to do your own query to get the values in this field. However, this is bad for performance (Service Reservations now get queried twice) and unnecessary. The better option is to simply add a fieldset on Service Reservation containing the checkbox field, and presto, the field is now populated.

Update formula fields before saving

You can use CFL to update formula fields in real-time, without forcing the user to save the reservation first.

Let’s say we have a field named My_Formula__c with formula B25__Account__r.Name + ': ' + B25__Contact__r.LastName.

First, create a handler that listens to updates on any field referenced by the formula.

// do this inside the customise method of your CFL: form.getField(B25__Reservation__c.B25__Account__c).onUpdate(new MyFormulaUpdater()); form.getField(B25__Reservation__c.B25__Contact__c).onUpdate(new MyFormulaUpdater());

Then, inside your handler, get the SObject record and pass it through Salesforce’s Formula.recalculateFormulas method.

// do this inside the handleEvent method of your handler class: B25.FormRecord theFormRecord = form.getActiveRecord(); SObject theSObjectClone = theFormRecord .getSObjectClone(); Formula.recalculateFormulas(new List<SObject>{theSObjectClone});

Finally, get the new value for the formula field and let the form update it by using the put method of B25.FormRecord.

// still inside the handleEvent method of your handler class: String theNewValue = theSObjectClone.My_Formula__c; theFormRecord.put(B25__Reservation__c.My_Formula__c, theNewValue);

Important to note is that although the put method can update formula field values displayed on the form, subsequent calls to get or getSObjectClone will not contain the updated value in the field, as illustrated here: