The Company Queue
In FinancialForce Accounting, companies play a central role in managing Salesforce sharing permissions to automatically partition accounting data. Sharing permissions control record level access, i.e. which of the records for each sObject are visible to each user. Approximately one quarter of the sObjects used in Accounting use the company model to control sharing, this includes many of the most commonly used sObjects such as Sales Invoices or Periods.
When a company is created an associated Queue (also referred to as a Group) is created. When a user selects a company he is made a member of that company queue, which in turn grants him access to sObject records that are owned by the company queue.
When new records (that use the company model) are created the owner of the record is assigned to be the company queue associated with the user’s selected company automatically. This restricts the visibility of that record to users who currently have the same company selected.
The companies that a user has selected are persistent between web browser sessions and are also used when using the product API. In many cases operations in Accounting require that only a single company be selected so that record changes are unambiguously for a single company.
Salesforce Queue objects are part of a set of objects termed ‘Setup Objects’. There are additional restrictions on when and how you may make changes to these types of objects that limit how you may change company using Accounting APIs. The CODAAPICompany_2_0 service provides a SetCurrentCompanies function to change a users selected companies but you can only use this from an isolated execution context, such as within a Queueable, Future or as part of Batch, otherwise a MIXED_DML_OPERATION exception will occur.
Accounting sObjects of Sales Invoice, Sales Credit Note, Purchase Invoice, Purchase Credit Note, Cash Entry and Journal all support an owner company override feature that allows a user specified Company to be set when a new record is created. To use this you must set the c2g__OwnerCompany__c field on the record to the company you wish to insert the new object into.