1

How do I use the json2apex tool. I generated an apex code and I am trying to split this in an apex class and testclass but get the error:

Method does not exist or incorrect signature: void parse(String) from the type invoicesTest

Class:

//
//Generated by AdminBooster
//

public class invoices{
    public cls_invoiceList[] invoiceList;
    class cls_invoiceList {
        public String customerId;   //12345abcd
        public String addressId;    //1000AA25
        public String invoiceId;    //c000X000021KuMi
        public String invoiceType;  //MontlyPayment
        public String invoiceTypeLocalized; //Pending
        public String invoiceDate;  //2016-08-14T00:00:00
        public String DueDate;  //2016-09-14T00:00:00
        public String invoiceNumber;    //123456
        public String startDate;    //2016-07-01T00:00:00
        public String endDate;  //2017-07-01T00:00:00
        public String Description;  //july 2016
        public Double amount;   //100.1
        public Double vatAmount;    //50.5
        public Double totalAmount;  //150.6
    }
    public static invoices parse(String json){
        return (invoices) System.JSON.deserialize(json, invoices.class);
    }
}

Testclass:


@isTest
public class invoicesTest {
    static testMethod void testParse() {
        String json=        '{'+
        '  "invoiceList": ['+
        ' {'+
        '"customerId": "12345abcd",'+
        '"addressId": "1000AA25",'+
        '"invoiceId": "c000X000021KuMi",'+
        '"invoiceType": "MontlyPayment",'+
        '"invoiceTypeLocalized": "Pending",'+
        '"invoiceDate": "2016-08-14T00:00:00",'+
        '"DueDate": "2016-09-14T00:00:00",'+
        '"invoiceNumber": "123456",'+
        '"startDate": "2016-07-01T00:00:00",'+
        '"endDate": "2017-07-01T00:00:00",'+
        '"Description": "july 2016",'+
        '"amount": 100.10,'+
        '"vatAmount": 50.50,'+
        '"totalAmount": 150.60'+
        '},'+
        '{'+
        '"customerId": "12345abcd",'+
        '"addressId": "1000AA25",'+
        '"invoiceId": "c000X000021KuMi",'+
        '"invoiceType": "MontlyPayment",'+
        '"invoiceTypeLocalized": "Pending",'+
        '"invoiceDate": "2016-08-14T00:00:00",'+
        '"DueDate": "2016-09-14T00:00:00",'+
        '"invoiceNumber": "123456",'+
        '"startDate": "2016-07-01T00:00:00",'+
        '"endDate": "2017-07-01T00:00:00",'+
        '"Description": "july 2016",'+
        '"amount": 100.10,'+
        '"vatAmount": 50.50,'+
        '"totalAmount": 150.60'+
        '},'+
        '{'+
        '"customerId": "12345abcd",'+
        '"addressId": "1000AA25",'+
        '"invoiceId": "c000X000021KuMi",'+
        '"invoiceType": "MontlyPayment",'+
        '"invoiceTypeLocalized": "Pending",'+
        '"invoiceDate": "2016-08-14T00:00:00",'+
        '"DueDate": "2016-09-14T00:00:00",'+
        '"invoiceNumber": "123456",'+
        '"startDate": "2016-07-01T00:00:00",'+
        '"endDate": "2017-07-01T00:00:00",'+
        '"Description": "july 2016",'+
        '"amount": 100.10,'+
        '"vatAmount": 50.50,'+
        '"totalAmount": 150.60'+
        '}'+
        '      ]}'+
        '';
        invoices obj = parse(json);
        System.assert(obj != null);
    }
    }
  • It should be invoices obj = invoices.parse(json); – Hemant Jain Jun 22 '18 at 13:25
  • @HemantJain please place this as the answer. Thanks! – Thomas Jun 22 '18 at 13:36
2

parse is a static method and its in a different class. So you need to reference using the class name.

So it should be called like this:

invoices obj = invoices.parse(json);
| improve this answer | |

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.