I have a output JSON which has object rows in a variable called values.


values=((01uo00000030BpcAAE, 01to0000001pRBx, 913840, test1, 100), 
        (01uo00000030BphAAE, 01to0000001pRBx, 9137, test2, 200)

Each row in the values variable is a row in an object. How do I return this as a list of sobject?

  • You need to create a class and use JSON.deserialize method. Can you add valid JSON string example? – vladdihoney Jun 30 '16 at 9:16

Can you please add your actual contents of JSON string here?

If you are not going to have JSON contents and you will have only List of List of String, then please check this code :-

// Consider, it is initialized as per your requirement.
List<List<String>> listOfOuterTokens = new List<List<String>>();

// Consider any sobject to store output; for the time being, we have considered Contact object.
List<Contact> listOfContacts = new List<Contact>();

// Consider, you know how the data is stored in the "listOfOuterTokens" so prepare this list accordingly.
List<String> listOfApiNames = new List<String>{'Name','Email','Title','Phone'};
Integer inSizeOfApiNames = listOfApiNames.size();

for( List<String> listOfInnerStringTokens : listOfOuterTokens ) {
    Contact recordContact = new Contact();

    Integer intSizeInnerStringTokens = listOfInnerStringTokens.size();
    Integer intInnerListIndex = 0;

    while( intInnerListIndex < inSizeOfApiNames && intInnerListIndex < intSizeInnerStringTokens ) {
        recordContact.put( listOfApiNames.get( intInnerListIndex), listOfInnerStringTokens.get( intInnerListIndex ) );
        intInnerListIndex ++;
    listOfContacts.add( recordContact );

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.