+ Start a Discussion
smriti sharan19smriti sharan19 

How to pass values from one method to another in Apex

I want to Pass a list named classList to another method within a class
Complete Requirement
Based on field values coming from case object after query, I want to create account and link the accountid to case. I have created two methods.
Method1 to validateCase
Method 2 to create account. 
I have created a List(caseList) at class level, iterated over list in method1(validateCase) and I want to get values of that in method2(createAccount).However, values of list is not coming in method 2. CaseList when debugging in method2 is not showing any result. 
public with sharing class AccountHandler  {
     public static List<Case> caseList = new List<Case>();
    public static Boolean validateClaim(Map<String, String>claimIdMap, Map<String,String>claimDateMap) {
        Map<String, String> claimIdToClaimDateMap = new Map<String, String>();
        Boolean flag = false;
        DateTime datetimeinquiry;
        String convertToStr;
        String dateStr;
        Date dformat;
        Date d2format;
        Set<String> tempList = new Set<String>();
        tempList = claimIdMap.keySet();
        for(String s : tempList){
            claimIdToClaimDateMap.put(claimIdMap.get(s), claimDateMap.get(s));
        System.debug('claimIdToClaimDateMap ' + claimIdToClaimDateMap);
        map<String,Date> myMap=new Map<String,Date>(); 
        caseList = [Select CaseNumber,Date_of_Injury__c,Insurer__c FROM Case where CaseNumber IN:claimIdToClaimDateMap.keySet()];
        for(Case c:caseList)
                date d = c.Date_of_Injury__c;
                myMap.put(c.CaseNumber, c.Date_of_Injury__c);
        for(String s : myMap.keySet()){
            dformat = Date.valueOf(claimIdToClaimDateMap.get(s));
            if(dformat == myMap.get(s)){
                flag = true;
                flag = false;
        return flag;

    public static Account createAccount(account accrec,List<Case> caseList) {
        List<Case> casesToUpdate = new List<Case>();
        system.debug('inside createaccount');
        system.debug('accrec'+ accrec);
        system.debug('caseList' + caseList);
            //insert accrec;
            //caselist jo banayi h isme jo account field h usme accrec id update kardo 
            //for each - iterate on c - c.acc = accrec.id;
            //update caseList;
            //user u = createUser(); 
            for (Case c: caseList) {
                system.debug('c: '+ c);
                c.Insurer__c = accrec.id;
            update caseList;
        catch(Exception ex) {
            throw new AuraHandledException(ex.getMessage());
        return accrec;

From where are you calling createAccount method?
smriti sharan19smriti sharan19
from LWC
smriti sharan19smriti sharan19
So firstly I am validating values coming from lwc in method1 and then if values are correct then again I am going to lwc and getting values for account and then creating account so both method are in sepeate threads because of which method2 is not getting caselist value
AbhishekAbhishek (Salesforce Developers) 
Check this once,


Another example,


It might help you.