Thursday, 7 May 2015

Creating a sales invoice with financial force (no current company)

Problem :-  Creating a sales invoice with financial force

How to set Current Company by UI:-

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

Test Class for Sales Invoice in Financial Force ( How to set current company by Code ) :-

private class salesInvoiceTestClass
 static testMethod void salesInvoiceTest() 
 Group testGroup = new Group(Name='test group', Type='Queue');
 insert testGroup;
 QueuesObject testQueue ; 
 System.runAs(new User(Id=UserInfo.getUserId()))
     List<queuesobject >  listQueue = new List<queuesobject >();
   queuesobject q1 = new queuesobject (, sobjecttype='Case'); 
   queuesobject q2 = new queuesobject (,                                                                 sobjecttype='c2g__codaAccountingCurrency__c'); 
   queuesobject q3 = new queuesobject (,                                                                 sobjecttype='c2g__codaPurchaseInvoice__c'); 
   queuesobject q4 = new queuesobject (, sobjecttype='c2g__codaCompany__c'); 
   queuesobject q5 = new queuesobject (, sobjecttype='c2g__codaYear__c'); 
   queuesobject q6 = new queuesobject (, sobjecttype='c2g__codaInvoice__c'); 
   insert  listQueue;

   GroupMember GroupMemberObj = new GroupMember();
   GroupMemberObj.GroupId =;
   GroupMemberObj.UserOrGroupId = UserInfo.getUserId();
   insert GroupMemberObj;

 c2g__codaCompany__c company = new c2g__codaCompany__c();
 company.Name = 'Test Record';
 company.JDE_Company_Code__c = '123';
 company.GLS_JE_Group_Number__c = '123' ;
 company.c2g__CashMatchingCurrencyMode__c = 'Test Account';
 company.c2g__YearEndMode__c = 'Test Code';
 company.c2g__ExternalId__c = 'ABCDE1234567876';
 company.c2g__LogoURL__c ='';
 company.c2g__ECCountryCode__c = 'AE' ;
 company.c2g__VATRegistrationNumber__c = 'Test 222.222.222 TVA' ;
 company.c2g__Website__c = '';
 company.c2g__Country__c ='US';
 company.ownerid = testGroup.Id;
 insert company;

 c2g__codaYear__c yr= new c2g__codaYear__c();
 yr.Name ='2015';
 yr.c2g__AutomaticPeriodList__c =  true;
 yr.c2g__OwnerCompany__c =;
 yr.c2g__ExternalId__c = 'yzsd1234';
 yr.c2g__NumberOfPeriods__c =11;
 yr.c2g__StartDate__c = - 10;
 yr.c2g__Status__c = 'Open';
 yr.c2g__PeriodCalculationBasis__c = '445';
 yr.c2g__YearEndMode__c = 'Full Accounting Code' ; 
 yr.c2g__UnitOfWork__c = 12;
 yr.ownerid = testGroup.Id;
 insert yr;

 c2g__codaPeriod__c prd = new c2g__codaPeriod__c();
 prd.Name ='Test2015';
 prd.c2g__ExternalId__c ='abdc12345';
 prd.c2g__StartDate__c =;
 prd.c2g__OwnerCompany__c =;
 prd.c2g__PeriodNumber__c ='123';
 prd.c2g__Description__c ='test Desc';
 prd.c2g__PeriodGroup__c = 'Q1';
 prd.c2g__PeriodNumber__c = '1';
 prd.c2g__YearName__c =;
 insert prd;

 c2g__codaUserCompany__c userCompany = new c2g__codaUserCompany__c();
 userCompany.c2g__User__c = userInfo.getUserId();
 userCompany.c2g__ExternalId__c = 'ABCDE1234567876';
 userCompany.c2g__UnitOfWork__c = 111 ;
 insert  userCompany;

 c2g__codaAccountingCurrency__c accCurrency = new c2g__codaAccountingCurrency__c();
 accCurrency.c2g__OwnerCompany__c =;
 accCurrency.c2g__DecimalPlaces__c = 2;
 accCurrency.Name = 'AED';
 accCurrency.c2g__Dual__c = true ;
 accCurrency.ownerid = testGroup.Id;
 insert accCurrency;

 c2g__codaExchangeRate__c exchRate = new c2g__codaExchangeRate__c();
 exchRate.c2g__ExchangeRateCurrency__c =;
 exchRate.c2g__OwnerCompany__c =;
 exchRate.c2g__ExternalId__c ='12323232';
 exchRate.c2g__Rate__c =44.55;
 exchRate.c2g__StartDate__c =;
 exchRate.c2g__UnitOfWork__c =10;
 insert exchRate;       

 c2g__codaGeneralLedgerAccount__c GLAcc = new c2g__codaGeneralLedgerAccount__c();
 GLAcc.Name = 'Retained Earnings';
 GLAcc.c2g__BalanceSheet1__c ='Balance Sheet'; 
 GLAcc.Description__c ='test Desc';
 GLAcc.c2g__ExternalId__c ='testID';
 GLAcc.Account_Level__c = 'CAB';
 GLAcc.Business_Unit__c = 'RG';
 GLAcc.c2g__ReportingCode__c = '1234567543333';
 GLAcc.c2g__UnitOfWork__c =123;
 GLAcc.Reconciliation_Frequency__c ='Quarterly';
 GLAcc.c2g__TrialBalance1__c = 'Balance Sheet' ;
 GLAcc.c2g__Type__c = 'Balance Sheet' ;
 GLAcc.X10_Digit_GLA__c = false;
 insert GLAcc;

 Account acc= new Account();
 acc.Name='Test Account';
 acc.c2g__CODAAccountsPayableControl__c = GLAcc.Id;
 insert acc;

 c2g__codaInvoice__c testInvoice = new c2g__codaInvoice__c();
 testInvoice.CurrencyIsoCode = 'USD'
 testInvoice.c2g__InvoiceDate__c =
 testInvoice.c2g__DueDate__c =
 testInvoice.c2g__Account__c = acc.Id
 testInvoice.c2g__OwnerCompany__c =
 testInvoice.ownerid = testGroup.Id
 insert testInvoice;            

Problem link :-


  1. There are some ; missing from the last few lines of this code, also fields Account_Level__c,X10_Digit_GLA__c, Business_Unit__c, Reconciliation_Frequency__c and Description__c on c2g__codaGeneralLedgerAccount__c are custom fields that other users won't have so would need to be removed. The same applies to the JDE prefixed fields on the company record and Account_Currency__c on the account record.
    Also, and probably the worst part, this creates a company but doesn't actually set it as the current company. So the error remains?

    1. I believe the fields you mentioned are present in your organization only, so if you have any custom unmanaged fields which you marked as required, you need to populate them.
      This solution presented by Amit works for us.

  2. I am trying to use this example but I have this error message:"The currency for the chosen Account does not exist as an Accounting Currency within the current Company". Seems that the fields has changed.
    Could someone help me?

  3. Nice Work!
    Your post helped me a lot!

  4. Wow! This is a great help! Thaks!

  5. Hi Amit,

    I need a test class that creates transactions and the transaction line items.
    Do you have any sample test class for that?

    Thanks in advance.


  6. Salesforce Service Cloud is about ensuring that businesses provide exceptional customer service. It's like having a virtual customer care team on hand 24 hours a day, seven days a week. Salesforce Service Cloud Implementation can be a challenging yet rewarding experience, but it is important to streamline their customer service operations, improve their agent productivity, and ultimately enhance their overall customer experience.

    With Salesforce Service Cloud Implementation, you can easily assist your businesses to leverage the power of Salesforce to achieve your business goals. Request a free consultation with an AblyPro expert to learn how Salesforce Service Cloud may help your company improve customer service and drive higher retention rates!