1

I have an Apex class OpportunityUpserter with a static method, where the static method makes a call to another static method in a class called IntegrationUtilities, as shown below. This gives me a compile error in VC Code Variable does not exist: IntegrationUtilities. For some reason, the Apex class IntegrationUtilities is not recognized from insertOpportunities method. I know that static methods can't access instance variables. But in this case, the static method is trying to access another static method in a different class. What could be the reason for this error?

(All the classes were created using the "SFDX: Create Apex Class" option in SF CLI and all classes have a metadata file.)

public with sharing class OpportunityUpserter {   
   @Future(callout=true)   
   public static void upsertOpportunities(Set<Id> opportunityIds, String action) {        
      Opportunity[] opportunitiesToUpsert = [SELECT Id, name, owner.name, servicenow_sys_id__c FROM Opportunity WHERE Id IN :opportunityIds];        
      insertOpportunities(opportunitiesToUpsert);           
   }   

   public static void insertOpportunities(Opportunity[] opportunitiesToInsert) {
      //code to make REST request goes here   
      sys_id = IntegrationUtilities.getFieldsFromResponse(response, action).get('sys_id');   
   }
}

public with sharing class IntegrationUtilities {      
   public static Map<String, String> getFieldsFromResponse(HttpResponse response, String action) {
           // more code here
           // return Map<String, String>     
   }
}
3
  • 3
    Is this only showing up as an error in VS Code, or do you get an error when you actually try to deploy it (to a scratch org or sandbox)? If you are getting an error on deploy, I think that you've clipped out too much of the surrounding context in OpportunityUpserter to pinpoint an issue. If it is erroring on deploy, my best guess right now is that it's either an issue of shadowing, or an invisible character that's snuck its way into one of these two classes.
    – Derek F
    Jun 24 at 1:23
  • 2
    One other thing to try is to deploy IntegrationUtilities (if you haven't already) and attempt to call IntegrationUtilities.getFieldsFromResponse() via anonymous apex.
    – Derek F
    Jun 24 at 1:24
  • 2
    Did you save IntegrationUtilities (or both) after adding your code to the shell that was created when you selected "SFDX: Create Apex Class"?
    – Moonpie
    Jun 24 at 1:28

1 Answer 1

1

Most probably you have an error inside IntegrationUtilities class and it's not compiled hence cannot be deployed to the org and cannot be referenced by another class.

My advice would be to push/deploy both classes to the org as the separate classes(without calling IntegrationUtilities class methods inside OpportunityUpserter). And check if they can be deployed.

1
  • The solution turned out to be simple. IntegrationUtilities class was not yet deployed to org! The error went away after I deployed it, with no other changes. Thank you!
    – yvoloshin
    Jun 24 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.