0

We are working with the Salesforce REST API for interacting with an installed FinancialForce package.

This process has been mostly painless right up until we needed to POST an invoice. The apex documentation suggests this is possible over api: http://help.financialforce.com/accounting-api-apex/2018.2/CODAAPISalesInvoice_10_0.htm#PostInvoice0

However, I'm turning to the community for help on how to accomplish this over REST. My first attempt was to just update the status for an invoice to "Complete".

si := sobjects.SalesInvoice{
    Status: "Complete",
}
err := client.Patch(ctx, invoiceId, si, nil)
if err != nil {
    return err
}

However, that just returns an error message saying, that this is not the correct way of doing these things:

[
  {
    "message": "You cannot change the status of an invoice.",
    "errorCode": "FIELD_CUSTOM_VALIDATION_EXCEPTION",
    "fields": [
      "c2g__InvoiceStatus__c"
    ]
  },
  {
    "message": "Object validation has failed. Sales Invoice: You cannot modify this invoice.",
    "errorCode": "FIELD_CUSTOM_VALIDATION_EXCEPTION",
    "fields": []
  }
]

Since this is a managed package there doesn't seem to be a good way to dig into what the "Post" button in the UI is actually doing. I believe I'm going to need to do something around creating a new rest resource like we did for rendering pdfs:

@RestResource(urlMapping='/pdf/*')
global class renderPDF {
    @HttpGet global static void process() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        res.responseBody = new PageReference('/apex/c2g__codainvoiceprint?id='+id).getContentAsPDF();
        res.headers.put('Content-Type', 'application/pdf');
        res.headers.put('Content-Length', res.responseBody.size()+'');
    }
}

Which is easy enough, I just am lacking the Salesforce / FinancialForce insights on what to do next.

  • Since this is a managed package, FinancialForce support may be your best resource. Are you sure you have applied your API user's permissions appropriately? FF may require specific Permission Sets to undertake this operation. – David Reed Apr 9 at 7:28
  • Thanks David, I actually do have a support ticket open. Will repost here my outcome. – Jesse Apr 9 at 14:12
0

This is possible by building a rest resource and using apex directly.

@RestResource(urlMapping='/postInvoice/*')
global class postInvoice {
    @HttpPost global static void process() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

        //post the invoice
        c2g.CODAAPICommon.Reference pRef = new c2g.CODAAPICommon.Reference();
        pRef.Id = id;

        c2g.CODAAPICommon_10_0.Context pContext = new c2g.CODAAPICommon_10_0.Context();
        c2g.CODAAPISalesInvoice_10_0.PostInvoice(pContext, pRef);
    }
}
  • Hi Jesse, was your answer as a result of the Financial Force support ticket, or purely your own work? – Simman May 12 at 7:16
  • It was the result of a consultant we are working with while moving to financial force, the ff Apex documentation and the sales force rest developers guide. Unfortunately I find FF support lacking for anything technical like this. – Jesse May 14 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.