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
RelaxItsJustCodeRelaxItsJustCode 

Does anyone know anything about writing code esp test code for FinancialForce?

I am having issues writing test code for the following code.  

Public Class CashMatchingFunctions
{
    Public static void UpdateAccountingInfo(Map<Id,c2g__codaCashMatchingHistory__c> oldMap, Map<Id,c2g__codaCashMatchingHistory__c> newMap)
    {
   
        List<Id> cmh_ids = new List<Id>();
        List<Id> cmh2_ids = new List<Id>();
        List<Id> tli_ids = new List<Id>();    
        List<Id> trn_ids = new List<Id>();    
 
        List<Id> SI_ids = new List<Id>();
        List<String> SI_Numbers = new List<String>();
        List<Id> Oppty_ids = new List<Id>();
       
        String SalesInvoiceNumber;
        Double HomeValue;
        Date MatchingDate;
        String OpportunityId;
        String TransactionType;
        String TransactionId;
        String TransactionIdUpdated;
        //Transaction_Type_Formula__c  Sales_Invoice_Number__c
       
        for(c2g__codaCashMatchingHistory__c c : newMap.Values())
        {
            if(c.CMH_Formula__c == 'Invoice' && c.Opportunity__c == null)
            {
                 cmh_ids.add(c.Id);
                 SI_Numbers.add(c.Sales_Invoice_Number__c);   
                 trn_ids.add(c.Transaction_Id__c);
                
            }
        }
       
    
         String SalesInvoiceNumber1;
         String TransactionIdProcess;
         String cmhid;
         String cmhform;
         for (c2g__codaTransaction__c t :[select id from c2g__codaTransaction__c where id in :trn_ids])
         {
             
              
           
               
               
                for(c2g__codaCashMatchingHistory__c cc2 :[select id, c2g__MatchingDate__c, CMH_Formula__c, Sales_Invoice_Number__c, Opportunity__c, c2g__HomeValue__c from c2g__codaCashMatchingHistory__c where Opportunity__c = '' and id = : cmh_ids])               
                {
                    c2g__codaCashMatchingHistory__c cc = [select id, c2g__MatchingDate__c, CMH_Formula__c, Sales_Invoice_Number__c, Opportunity__c, c2g__HomeValue__c from c2g__codaCashMatchingHistory__c where Opportunity__c = '' and Sales_Invoice_Number__c = : cc2.Sales_Invoice_Number__c];
                    HomeValue = cc.c2g__HomeValue__c;
                    MatchingDate = cc.c2g__MatchingDate__c;
                    cmhid = cc.id;
                    cmhform = cc.cmh_formula__c;
                    SalesInvoiceNumber1 = cc.Sales_Invoice_Number__c;
                }
                if(cmhform == 'Invoice')
                {
                List<Accounting__c> AccountingRecordsToInsert = new List<Accounting__c>();
                Accounting__c newAccountingInfo= new Accounting__c();

                c2g__codaInvoice__c tt = [select id, Name, c2g__Opportunity__c from c2g__codaInvoice__c where name = : SalesInvoiceNumber1];
                SalesInvoiceNumber1 = tt.Name;
               
                OpportunityId = tt.c2g__Opportunity__c;

                newAccountingInfo.Opportunity__c = OpportunityId;
                newAccountingInfo.Amount__c = HomeValue;
               
                newAccountingInfo.Date__c = MatchingDate;
     
                AccountingRecordsToInsert.add(newAccountingInfo);
                              
                if(AccountingRecordsToInsert.size() > 0)
                {
                newAccountingInfo.Invoice_Number__c = SalesInvoiceNumber1;
                newAccountingInfo.RecordTypeId =  ServiceClass.getRecordTypesNameMap('Accounting__c').get('Paid').Id;
                newAccountingInfo.Type__c = 'Paid';
                    Insert(AccountingRecordsToInsert);
                }     
                List<c2g__codaCashMatchingHistory__c> CMH_RecordsToUpdate = new List<c2g__codaCashMatchingHistory__c>();
       
                            for(c2g__codaCashMatchingHistory__c cmh2 :[Select id, Opportunity__c from c2g__codaCashMatchingHistory__c where Id in :cmh_ids])
                            {
                                if(cmhid == cmh2.id)
                                {
                                cmh2.Opportunity__c = OpportunityId;
                                CMH_RecordsToUpdate.add(cmh2);
                                }
                            }
                            if(CMH_RecordsToUpdate.size() > 0)
                            {
                                Update CMH_RecordsToUpdate;
                            } }

         }
       
                
            
       
    }
------------------------------------------------------- Here is the test code 

@isTest
private class PostAndMatchAction_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
    @isTest(seeAllData=true)
    static void invoiceTest(){
    String AccountId;
    String InvoiceId;
    String CashEntryId;
    String CashEntryLineItemsId;
        try{


    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;

    AccountId = a1.id;

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

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

User u1 = [SELECT Id FROM User WHERE Alias='APSFin'];
     System.RunAs(u1){
    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 = a1.id,
    c2g__Opportunity__c = o1.id,
                c2g__InvoiceDate__c = Date.today()
               
            );
            insert newInvoice;
           InvoiceId = newInvoice.id;
            List<c2g__codaInvoiceLineItem__c> newInvoiceLines = new List<c2g__codaInvoiceLineItem__c>{
                new c2g__codaInvoiceLineItem__c(
                    c2g__Invoice__c = newInvoice.id,
                    c2g__Product__c = '01t70000000oPMAAA2'
                )
            };
            insert newInvoiceLines;
           
            //Post it!
            update new c2g__codaInvoice__c(id = newInvoice.id,c2g__InvoiceStatus__c = 'Complete');
              system.assert(true,'WIN');         
        }catch(Exception e){
            if(softFail)
                System.debug(LoggingLevel.Error,'Soft fail enabled. Test marked as passed but it really failed with '+e.getMessage());
            else
                throw e;
        }
        try{
        string Bank_Account_id = 'a0y70000001qykc';
        c2g__codaCashEntry__c cashEntry = new c2g__codaCashEntry__c();
        cashEntry.c2g__BankAccount__c = BANK_ACCOUNT_ID;
        List<c2g__codacashentrylineitem__c> cashEntryLineItems = new List<c2g__codacashentrylineitem__c>();
        c2g__codaCashEntryLineItem__c cashEntryLineItem = new c2g__codaCashEntryLineItem__c();
        cashEntryLineItem.c2g__Account__c = AccountId;
cashEntryLineItem.c2g__CashEntryValue__c = 1.00;
cashEntryLineItems.add(cashEntryLineItem);
//Execute DML to insert Cash Entry
insert cashEntry;
CashEntryId = cashEntry.id;
for(c2g__codaCashEntryLineItem__c cashEntryLineItem2 : cashEntryLineItems)
{
    cashEntryLineItem2.c2g__CashEntry__c = cashEntry.Id;
}
insert cashEntryLineItems;
List<c2g__codaCashEntryLineItem__c> CashEntryLineItemsIds = new List<c2g__codaCashEntryLineItem__c>();
//CashEntryLineItemsIds.add(cashEntryLineItems.id);
   
//////////////////////////////////////////////////////////////////////////////
List<string> documentRefs = new List<string>();
documentRefs.add([select Id, Name from c2g__codaInvoice__c
where Id = :InvoiceId].Name);
documentRefs.add([select Id, Name from c2g__codaCashEntry__c
where Id = :CashEntryId].Name);
List<c2g__codatransactionlineitem__c> transactionLinesToMatch = [
    select
        Id,
        c2g__AccountValue__c
    from c2g__codaTransactionLineItem__c
    where
        c2g__Transaction__r.c2g__DocumentNumber__c in :documentRefs and
        c2g__LineType__c = 'Account'
];


c2g.CODAAPICommon_6_0.Context context = new c2g.CODAAPICommon_6_0.Context();
c2g.CODAAPICashMatchingTypes_6_0.Configuration configuration = new c2g.CODAAPICashMatchingTypes_6_0.Configuration();
configuration.Account = c2g.CODAAPICommon.getRef(AccountId, null);

configuration.MatchingCurrencyMode = c2g.CODAAPICashMatchingTypes_6_0.enumMatchingCurrencyMode.Account;
configuration.MatchingDate = System.today();
configuration.MatchingPeriod = c2g.CODAAPICommon.getRef('a28700000004ZLa', null);
List<c2g.codaapicashmatchingtypes_6_0.item> items = new List<c2g.codaapicashmatchingtypes_6_0.item>();
for (c2g__codaTransactionLineItem__c transactionLine : transactionLinesToMatch)
{
    c2g.CODAAPICashMatchingTypes_6_0.Item item = new c2g.CODAAPICashMatchingTypes_6_0.Item();
    item.TransactionLineItem = c2g.CODAAPICommon.getRef(transactionLine.Id, null);
    item.Paid = 1.00;
    item.Discount = 0; // No discount in this example
    item.WriteOff = 0;  // No write off in this example
    items.add(item);
}

c2g.CODAAPICashMatchingTypes_6_0.analysis analisysInfo = new c2g.CODAAPICashMatchingTypes_6_0.analysis();
// analisysInfo.DiscountGLA = ...
// analisysInfo.DiscountDimension1..4 = ...
// analisysInfo.WriteOffGLA = ...
// analisysInfo.WriteOffDimension1..4 = ...
// analisysInfo.CurrencyWriteOffGLA = ...
// analisysInfo.CurrencyWriteOffDimension1..4 = ...
c2g.CODAAPICommon.Reference matchReference = c2g.CODAAPICashMatching_6_0.Match(context, configuration, items, analisysInfo);
       system.assert(true,'WIN');         
     //
     system.assert(TRUE,'No Error');
            }
       catch( exception e )
            {
            
            }
  
   
   
   
    }
}

Please help if you can.  So far I hate FFDC''s API.

Thank you,
S

James LoghryJames Loghry
Have you tried reaching out to anyone from Financial Force? Several of the developers frequent these boards and Salesforce Stack Exchange as well.