I am writing code that calls an API to get external client info. I'm at the point where I have it working but I am wondering if there is a more efficient way to save the data to the Account object. Right now I am iterating through the list I have and updating each account but I am hitting governor limits pretty easily:
List<ParseAdminResponse> acctList = ParseAdminResponse.parse(response.getBody());
for(Integer i = 0; i < acctList.size(); i++){
if(acctList[i].Success = true){
acctId = acctList[i].SfAccountId;
version = acctList[i].ClientVersion;
Date todaysDate = system.today();
// Query for the account
Account queriedAccount = [SELECT Version__c
FROM Account
WHERE id = :acctId];
// Update the account's version
queriedAccount.Version__c = version;
queriedAccount.Last_Admin_Check__c = todaysDate;
update queriedAccount;
} else{
system.debug(acctList[i].ErrorMessage);
}
}
Is there a better way than saving the results I get one at a time?
Boolean value; if(value = true)
; this is an assignment, and will result in the if statement always being true (and value would be set to true). The code should beif(acctList[i].Success == true)
. or even justif(acctList[i].Success)
, because Boolean values are already Boolean values.