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
Snehil22Snehil22 

Unable to add multiple records in a list.

Hi,

In the below code, I am trying to send one header(Account) and multiple lines(Case). I am querying cases and adding it to a list(caseObj). The method which i am calling in the main class requires 2 parameters(String,List), so I am adding multiple cases in a list(ListLines).

The issue is that the list is getting the latest values and not the values of all the queried records. Please Help.

public class WMTestWebservice{
 
@future(callout = true)
    public static void WMTest(set<string> psoid){
   
        Account accObj=[select id,Name
                   
        from Account where Id=:psoid];
       
             
        List<Case> caseObj=[select id,Subject
                   
        from Case where Account.Id=:psoid];
             
      
    wmAppDev02AmHealthGeComSnehilPa.Snehil_Parts_Port  mainClass = new wmAppDev02AmHealthGeComSnehilPa.Snehil_Parts_Port ();
           
    wmAppDev02AmHealthGeComSnehilPa.Header header = new wmAppDev02AmHealthGeComSnehilPa.Header();
   
    wmAppDev02AmHealthGeComSnehilPa.Lines line = new wmAppDev02AmHealthGeComSnehilPa.Lines();
   
    List<wmAppDev02AmHealthGeComSnehilPa.Lines> ListLines = new wmAppDev02AmHealthGeComSnehilPa.Lines[150];
     
   
   
    mainClass.inputHttpHeaders_x = new Map<String, String>();

    String myCred1 = '******';
    String myCred2 = '******';
   
    Blob headerValue = Blob.valueOf(myCred1+':'+myCred2);
    String authorizationHeader = 'Basic ' +EncodingUtil.base64Encode(headerValue);
 
    mainClass.inputHttpHeaders_x.put('Authorization',authorizationHeader);
    mainClass.timeout_x=120000;
       
       
    header.name = accObj.Name;
    header.id   = accObj.id;
  
    integer i=0;
   
    for(Case cs: caseObj){ 
    
    line.EID    = cs.id;
    line.laptop = cs.Subject;
                   
    ListLines.add(i,line);// I am adding multiple cases in this list.
   
    system.debug('<<<<<ListLinesInsideLoop<<<<<'+ListLines);
   
    i = i+1;
      
     }
             
    system.debug('<<<<<ListLines<<<<<'+ListLines);   
    
   
    mainClass.ProcessPartOrder(header,ListLines);
       
   
   
    }
       
  }


nitin sharmanitin sharma
Hi ,

It looks like like you are passing Account ids from the trigger to the WMtest method. and then you want to query all the aacoaiated cases to those account.If that is what u intent to do than change your query to

List<Case> caseObj=[select id,Subject  from Case where AccountID=:psoid];

or
list<case> li=[Select id ,name,(select id,name from cases) from  account where id in:psoid]


now you can loop through the account  as well child records(means case records) and put them in them in the seperate lists and then pass it as parmeter to the method.