We're using the Financial Force for our accounting package within Salesforce, and have written a new class for a change we're implementing which has nothing to do with the Sales Invoice object. However, when we tried to deploy the change set, an error occurred on the already deployed trigger on the Sales Invoice object with a working Test Class. The error message on the deployment log shows:

Run Failures: scmffa_SalesInvoiceTriggerTest.CodeCoverageTest System.DmlException: Update failed. First exception on row 0 with id a28i0000005KabVAAS; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, c2g.ffb_SalesInvoice: execution of BeforeUpdate caused by: c2g.CODAException: The company must be one of the current companies.|codaCompany__c|null|2|0|

The trigger above was provided by SCM with a working Test Case, but it's throwing an error with The company must be one of the current companies. error. After some digging, I found the following:

Solution:

The problem is that the user who is deploying the change set does NOT have the default company set. You can technically rewrite the Test Case to create a c2g__codaCompany__c object and assign it within the Apex Test case, but the easier solution is to (1) create a user company, and (2) select the company for that user. This should already be done for the user anyway. Also, it's important to use @isTest(SeeAllData=true) so that you don't have to dynamically create the company within your test case.

  1. Click on the + (Plus) Tab, and choose User Companies menu item.
  2. Salesforce Plus Tab

  3. Create a new User Company for the user.
  4. User Companies

  5. Login as the user who will be deploying the change set, and Select a default Company for the user.
  6. Select Company

  7. Setting up a company in a test environment is a complex process, so you may want to add an annotation @isTest(SeeAllData=true). This annotation allows the test class to access the User Company specified from (1) through (3) above.

By creating a user company and selecting the default company for the user who will be deploying the change, The company must be one of the current companies error will disappear.

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment