function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

creating a sales invoice with financial force.

Hi everyone,


Our Company is using financial force accounting system, and I just wrote a trigger on the sales invoice object. Now when I wrote a test class for it, I use the code below:


c2g__CodaInvoice__c salesinvoice = new c2g__CodaInvoice__c();
//set values for the invoice
c2g__Opportunity__c =;
c2g__Account__c =;// opp and acc are already defined
... insert salesinvoice;

 But when I run the test, I always get an error message "no current company". Does anybody know what causes this error and how to get rid of it? Thanks a lot!!

Vardhan GuptaVardhan Gupta

I am getting the same error.


I am trying to create a simple test class, and am getting the same error. I have populated all the required fields..


Were you able to resolve it? 


Any feedback would be greatly appreciated.

This works for me.....

private class PostAction_Test{
    static final boolean softFail = false; //if true tests will fail softly - that is they will not be marked as failed but may not contribute full code coverage
    static void invoiceTest(){


    String CurrentUser;
    CurrentUser = UserInfo.getUserId();

    Account a1 = new Account(recordtypeid = ServiceClass.getRecordTypesNameMap('Account').get('Default').Id,Name = 'Test Acct', Industry = 'Federal',c2g__CODAAccountsReceivableControl__c = 'a1X7000000125BnEAI' );
    insert a1;

    Opportunity o1 = new Opportunity(Bill_To_Account__c =, Payment_Terms2__c= '100% Shipping',Payment_Terms__c= 'net 30', Amount = 10.00, NextStep = 'Quote',Name = 'Test Oppty', AccountId =, recordtypeid =     ServiceClass.getRecordTypesNameMap  ('Opportunity').get('Sales Quote (FL)').Id, Type = 'New Business', StageName = 'Quote', CloseDate =;
     insert o1;

    OpportunityLineItem OLI = new OpportunityLineItem(totalPrice = 1.00, PriceBookEntryId = '01u70000001VydaAAC',OpportunityId =, Quantity = 50);
        insert OLI;    

User u1 = [SELECT Id FROM User WHERE Alias='APSFin'];
    o1.recordtypeid = ServiceClass.getRecordTypesNameMap('Opportunity').get('Closed Won').Id;
        o1.StageName = 'Closed Won';

                update o1;}

            c2g__codaInvoice__c newInvoice = new c2g__codaInvoice__c(
                c2g__Account__c =,
    c2g__Opportunity__c =,
                c2g__InvoiceDate__c =
            insert newInvoice;
            List<c2g__codaInvoiceLineItem__c> newInvoiceLines = new List<c2g__codaInvoiceLineItem__c>{
                new c2g__codaInvoiceLineItem__c(
                    c2g__Invoice__c =,
                    c2g__Product__c = '01t70000000oPMAAA2'
            insert newInvoiceLines;
            //Post it!
            update new c2g__codaInvoice__c(id =,c2g__InvoiceStatus__c = 'Complete');
        }catch(Exception e){
                System.debug(LoggingLevel.Error,'Soft fail enabled. Test marked as passed but it really failed with '+e.getMessage());
                throw e;

Michael ChitayatMichael Chitayat
You need to set a Current Company. 

First create a c2g__codaCompany__c record. Then Activate it using the custom button on the record page. 
Create a 'User Company' assigning your user to that company from the related list at the bottom of the page. 
Then go to Setup / Customize / Home / Home Page Layouts / Page Layout Assignment and assign the FinancialForce Layout to your profile.
Go to a non-setup page where you can see the left sidebar. The left sidebar near the top should show your 'current company'. 
If you have no 'current company',  a link saying 'Current Company not set' should appear there instead.
Click on the link and select a company from the list of companies that you have created.
Then create your invoice(s) as required.  
Thanks for the reply. I contact with financialforce, and they sadi it's very complex process to set up company for testing, so I have to add an annotation @isTest(SeeAllData=true). I think that's the quickest way to solve the problem.
Amit Chaudhary 8Amit Chaudhary 8
I have fixed this issue. Please reffer below blog

PS: if this answers your question then Please hit Like and mark it as solution!

Amit Chaudhary
Thanks Michael, your answer saved our day :)