Request Body represents the id and name of the records that should be updated. I am giving more than 100 Records in Request Body via Postman using a POST method. When I do so I get an error response:
[ { "errorCode": "APEX_ERROR", "message": "System.LimitException: Too many SOQL queries: 101\n\nClass.restresource100.updateCase1: line 30, column 1\nClass.restresource100.updateCase: line 16, column 1" } ]
For that I have tried the following Apex Class
:
@RestResource(urlMapping='/Account100/')
global with sharing class restresource100
{
public list<account1> account1= new list<account1>();
@Httpput
global static void updateCase(){
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
system.debug(req);
Blob body = req.requestBody;
system.debug(body);
string body1=body.tostring();
system.debug(body1);
restresource100 obj = restresource100.parse(body1);
system.debug(obj);
updateCase1(obj);
}
public static list<account> updateCase1(restresource100 iu)
{
list<account> fg = new list<account>();
for(account1 i :iu.account1){
system.debug(i.id);
list<account> acc =[select id,name from account where id = :i.id];
system.debug(acc);
for(account cd:acc)
{
cd.Name=i.name;
fg.add(cd);
}
}
update fg;
return null;
}
public class account1
{
public string name;
public id id;
}
public static restresource100 parse(String json)
{
return(restresource100)System.JSON.deserialize(json, restresource100.class);
}
}