I have code that compiles and executes fine in execute anonymous and when combined but seems to have a weird issue otherwise:
private static Boolean updateWorkOrder(Id workOrderId, String responseBody) {
if(workOrderId == null || responseBody == null || !responseBody.contains('REQ -'))
Integer pos = responseBody.indexOf('REQ -');
String install = responseBody.substring(pos,responseBody.length());
WorkOrder wo = new WorkOrder(Id = workOrderId, Snap_Install__c = install);
Database.SaveResult sr = Database.update(wo,false);
if(sr.isSuccess()) return true;
else return false;
return false;
}
I keep getting a "Variable Does Not Exist" error. With the code below, I get pos doesn't exist on the line below it (install = ...).
If I change the line to the below, I get an error that install does not exist on the wo line.
String install = responseBody.substring(responseBody.indexOf('REQ -'),responseBody.length())
And so on... The code runs just fine when I put it in execute anonymous.
I can get the class to compile as follows:
if(Database.update(new WorkOrder(Id = workOrderId, Snap_Install__c = responseBody.substring(responseBody.indexOf('REQ -'),responseBody.length())),false).isSuccess()) return true;
else return false;
return false;
But this is pretty ugly as shit. Does anyone have any idea what is going on here?