Updated: Nov 19, 2020
When we need to update the fields of records that have been created out of Forceea (e.g. we retrieve records from Salesforce or we create records "manually"), we can use the constructors FObject(record), FObject(records), FObject(record,groupName), or FObject(records,groupName).
These constructors will initialize a new FObject with the records as “inserted” FObject records, which allows to update the records using the method setDefinitionForUpdate.
Then you can use updateFields/updateRecords.
Let's suppose you have created some accounts and you retrieve them with
List<Account> accounts = [SELECT Name, AnnualRevenue FROM Account];
If you want to update the Annual Revenue values with Forceea, you can initialize a new FObject with
FObject obj = new FObject(accounts);
Now you can use the usual tools for updating your field(s)
obj .setDefinitionForUpdate(Account.AnnualRevenue, 'random type(number) from(1000) to(10000) scale(0)') .updateFields('') .updateRecords(true);
As you can see, the Annual Revenue will get a random decimal value between 1,000 and 10,000 with 2 decimal places (e.g. 1,250.23).
The method updateFields('') will replace the existing field values with the new generated values, but what does the '' mean?
Forceea accepts 3 different parameters in updateFields:
If there is no argument, e.g. updatedFields(), or the argument is null, e.g. updateFields(null), the method will update the last created records.
If the argument is blank, e.g. updateFields('') or updateFields(' '), the method will update the inserted records of the global group.
If the argument is not blank, e.g. updateFields('MyGroup'), the method will update the inserted records of MyGroup group.
Keep in mind that only inserted records can belong to a global group or a named group. When we used the constructor, we didn't define any group, so the accounts were assigned to the global group.
That's the reason we used ''; we said: hey Forceea, please update the inserted fields of the "global group".
If we had used the constructor
FObject obj = new FObject(accounts, 'accountsGroup');
we could of course have used updateFields('accountsGroup').