
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 the list.
system.debug('<<<<<ListLinesInsideLoop<<<<<'+ListLines);
i = i+1;
}
system.debug('<<<<<ListLines<<<<<'+ListLines);
mainClass.ProcessPartOrder(header,ListLines);
}
}