1

I have a web service method to load invoices into Salesforce for product type A and I am trying to modify the same method for product type B invoices. However the Product type B has couple more parameters than product type A. We cannot change the client side call for product type A as it requires a lot of change process. I see that we cannot overload a webservice method and Salesforce does not allow defaulting a method parameter.

Code:

webservice static String createInvoice( String invoiceNumber,String invoiceType,Decimal Amount, String invoiceCurrency,String ProductType,String customerAccountNo, Date invoiceDate, String invoiceMonth,Date paymentDueDate, Decimal volume){
    Invoice__c invoice = new Invoice__c();
    invoice.Invoice_Number__c = invoiceNumber;
    invoice.Invoice_Type__c = invoiceType;
    other value assignments....
    insert invoice;
    if(invoice.Id != null){
        return invoice.Id;
    }
    else{
        return error;
    }
}

Can you please suggest an alternative please?

  • Could you provide code or examples? One method to do this is have two webservice methods, and call the type B method from the type A method - The product A would call a simpler version, and then call the type B method with default arguments. This could also be done if they shared the same underlying private method. – HungryBeagle May 25 '16 at 14:45
  • webservice static String createInvoice( String invoiceNumber,String invoiceType,Decimal Amount, String invoiceCurrency,String ProductType,String customerAccountNo, Date invoiceDate, String invoiceMonth,Date paymentDueDate, Decimal volume){ Invoice__c invoice = new Invoice__c(); invoice.Invoice_Number__c = invoiceNumber; invoice.Invoice_Type__c = invoiceType; other value assignments.... insert invoice; if(invoice.Id != null){ return invoice.Id; }else{ return error; }} – Ganesh Raj May 25 '16 at 14:57
  • can I create another web service call lets say createInvoice_ProdB and inside it can I call createInvoices method directly? – Ganesh Raj May 25 '16 at 15:00
  • Yes - You can do that. – HungryBeagle May 25 '16 at 17:22

Your Answer

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

Browse other questions tagged or ask your own question.