function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jishan royjishan roy 

How to use deserialize JSON in wrapper class.

i want to know how to deserialize json by using wrapper class to update multiple account related records like contact, opportunity, and case.

here is my wrapper class:

public with sharing class contactController {
@AuraEnabled(cacheable=true)
public static List<accWrapper> getAccountRelatedRecord(Id recordId){
List<Contact> conlist = new List<Contact>();
List<Opportunity> oppolist = new List<Opportunity>();
List<Case> clist = new List<Case>();
List<accWrapper> acclist = new List<accWrapper>();
try{
    conlist= [SELECT Id , Lastname,FirstName,Email,Phone FROM Contact WHERE AccountId =: recordId];
        oppolist = [SELECT Id, Name, CloseDate, Amount, StageName,AccountId  FROM Opportunity WHERE AccountId =:recordId ];
        clist = [SELECT Id, Status, Type, ContactId, CaseNumber FROM Case WHERE AccountId =: recordId];
        system.debug('Showlists>>>>>' + conlist);
        List<accWrapper> aclist = new List<accWrapper>();
        for (Contact cons : conlist){
            accWrapper aw = new accWrapper();
            aw.contactRecord = cons;
            aclist.add(aw);
        }
        for (Opportunity opps : oppolist){
            accWrapper aw = new accWrapper();
            aw.opportunityRecord = opps;
            aclist.add(aw);
    }
   
    for (Case cs : clist){
            accWrapper aw = new accWrapper();
            aw.caseRecord = cs;
            aclist.add(aw);
    }
    system.debug(aclist.size());
        return aclist;
}catch (Exception e){
    throw new AuraHandledException(e.getMessage());
}
}
public class accWrapper{
    @AuraEnabled
    public Contact contactRecord{get;set;}
    @AuraEnabled
    public opportunity opportunityRecord{get;set;}
    @AuraEnabled
    public case caseRecord{get;set;}
}
    }
SwethaSwetha (Salesforce Developers) 
HI Jishan,
Recommend reviewing https://salesforce.stackexchange.com/questions/176866/json-deserialize-with-wrapper-class

Thanks