+ Start a Discussion

API Salesforce - Create Sales Invoice and Cash Entry



I am encountering difficulties with creating a sale invoice (c2g__codaInvoice__c) and cash entry (c2g__codaCashEntry__c). Both objects have a lineitem object (c2g__codaInvoiceLineItem__c, c2g__codaCashEntryLineItem__c).

I first set the invoice's fields and create it. However I get the following error message:


stdClass Object
    [errors] => stdClass Object
            [message] => Object validation has failed.

    [id] => 
    [success] => 

Am I suppose to create invoice line item first (c2g__codaInvoiceLineItem__c)? This is a bit confusing. I thought that I would first set the c2g__Account__c for a sale invoice and get the id of the invoice and then create an invoice line item(s) for the corresponding invoice id. 

According to the architecture, the opportunity if is linked to the sale invoice object.I have already code my opportunity with its opportunity line items so I do have the opportunity id in hand. 


In PHP, how do you create a sale invoice given opportunity and account info? I assume once I figure out the sales invoice I would be able to figure out the cash entry which is similar with the line entry. 


FYI - According to financial force, these functionalities can be developed with API salesforce. Do I need to download some kind of financial force extension package?


Tony P.ax1100Tony P.ax1100

I think you are thinking of it the right way - you need to create the parent record first, then use its id to create the line item record.  Based on the error, it looks like there is a validation rule on the c2g__codaInvoice__c object.  Just go into that object in Salesforce and see what it is looking for - probably a missing value or something.


I have already checked. There is no validatin rule for this object that's why this error is a bit odd to me.

Try setting the following fields on the Sales Invoice record:

c2g__codaInvoice__c salesInvoice = new c2g__codaInvoice__c();
salesInvoice.c2g__InvoiceStatus__c = 'In Progress';
salesInvoice.c2g__Account__c = '001xxxxxxxxxxxx';
salesInvoice.c2g__Period__c = 'a1Hxxxxxxxxxxxx';
salesInvoice.c2g__InvoiceCurrency__c = 'a0Fxxxxxxxxxxxx';
insert salesInvoice;