Skip to main content
language
Source Link
JCD
  • 3.4k
  • 2
  • 27
  • 37

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?

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 ugly as shit. Does anyone have any idea what is going on here?

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. Does anyone have any idea what is going on here?

Source Link
Apexing
  • 344
  • 1
  • 3
  • 12

Salesforce's Apex Compiler Throwing Phantom Error

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 ugly as shit. Does anyone have any idea what is going on here?