0

I have created a component which takes users input and when the submit button is hit I want the component to insert my transaction__c records from the created JSONList,

As it stands my example json looks like so for 2 transaction records:

{"sobjectType":"Transaction__c","Contract__c":"8004E000000DMwqQAG","Related_Asset__c":"02i4E0000009hBdQAI","Billable_Month__c":"2017-11-06","Number_of_Transactions__c":"10000"},{"sobjectType":"Transaction__c","Contract__c":"8004E000000DUehQAG","Related_Asset__c":"02i4E000000A2ARQA0","Billable_Month__c":"2017-11-06","Number_of_Transactions__c":"500"}

This list is past into the apex controller "insertTransactions" method which I currently have like so:

 @AuraEnabled
    public static void insertTransactions(String tListJSON) {
        try{
        //insert tListJSON;
        }
        catch(exception e){
            System.debug('error inserting transactions @ ' + e);
        }
    }

I have tried creating a json2apex class but the __c isn't accepted so what are my options here for getting this to insert correctly?

Thanks

3

You need to use the JSON class in Apex to deserialize it:

JSON.deserialize(tListJSON, List<Transaction__c>.class);
1
  • Another option is to use a wrapper class as you would be 100% sure on what to expect with serialize/de-serialize
    – Raul
    Nov 6 '17 at 13:58

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.