0

I am having an issue where I have an invocable method that is receiving an Id for a record (in practise it will be receiving it from a flow), then based on that Id it searches for the object using a query. In the test class, I create a test record in the code and pass this Id through and the code works fine. But if I pass the Id for an actual record through, it returns nothing and I end up with an error later on in the code when it tries to reference something that isn't there.

I have tried setting the code 'without sharing' and 'with sharing' and even setting it from public to global and still no luck. The code is currently running on an Admin account in a sandbox so I am not sure how permissions would be an issue but this is my best bet on what's happening.

public without sharing class ConvertOvernightBooking {
@InvocableMethod
public static List<Nationwide_Address__c> ConvertBooking(List<Id> dublinAddressId) {
    // Query Dublin Address info
    List<Dublin_Address__c> area = new List<Dublin_Address__c>();
    System.debug('Received Id: ' + dublinAddressId[0]);
    // System.debug('Area before = ' + area);

    area = [SELECT Id, Name FROM Dublin_Address__c WHERE Id = :dublinAddressId[0]];
    
    System.debug('Area after = ' + area);

Here is some of the logs of what I am seeing:

14:13:25.270 (287725978)|METHOD_ENTRY|[7]|01p5E000005ffLW|ConvertOvernightBooking.ConvertBooking(List<Id>)
14:13:25.270 (287770474)|VARIABLE_SCOPE_BEGIN|[3]|dublinAddressId|List<Id>|true|false
14:13:25.270 (287990817)|VARIABLE_ASSIGNMENT|[3]|dublinAddressId|["a0G5E00000AIBOKUA5"]|0x6c671d67
14:13:25.270 (288022580)|SYSTEM_MODE_ENTER|true
14:13:25.270 (288039271)|HEAP_ALLOCATE|[5]|Bytes:5
14:13:25.270 (288052926)|STATEMENT_EXECUTE|[3]
14:13:25.270 (288056993)|STATEMENT_EXECUTE|[5]
14:13:25.270 (288154767)|HEAP_ALLOCATE|[5]|Bytes:4
14:13:25.270 (288279148)|VARIABLE_SCOPE_BEGIN|[5]|area|List<Dublin_Address__c>|true|false
14:13:25.270 (288307444)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
14:13:25.270 (289447009)|VARIABLE_ASSIGNMENT|[5]|area|[]|0x28dd0072
14:13:25.270 (289475564)|STATEMENT_EXECUTE|[6]
14:13:25.270 (289492157)|HEAP_ALLOCATE|[6]|Bytes:13
14:13:25.270 (289514561)|HEAP_ALLOCATE|[6]|Bytes:18
14:13:25.270 (289547926)|HEAP_ALLOCATE|[6]|Bytes:4
14:13:25.270 (289631546)|HEAP_ALLOCATE|[6]|Bytes:18
14:13:25.270 (289665933)|HEAP_ALLOCATE|[6]|Bytes:31
14:13:25.270 (289697227)|USER_DEBUG|[6]|DEBUG|Received Id: a0G5E00000AIBOKUA5
14:13:25.270 (289710967)|STATEMENT_EXECUTE|[9]
14:13:25.270 (289715084)|HEAP_ALLOCATE|[9]|Bytes:58
14:13:25.270 (289734201)|HEAP_ALLOCATE|[9]|Bytes:4
14:13:25.270 (289746604)|HEAP_ALLOCATE|[9]|Bytes:7
14:13:25.270 (289757178)|HEAP_ALLOCATE|[9]|Bytes:18
14:13:25.270 (289774385)|HEAP_ALLOCATE|[9]|Bytes:4
14:13:25.270 (290141519)|SOQL_EXECUTE_BEGIN|[9]|Aggregations:0|SELECT Id, Name FROM Dublin_Address__c WHERE Id = :tmpVar1
14:13:25.270 (300437986)|SOQL_EXECUTE_END|[9]|Rows:0
14:13:25.270 (300505597)|HEAP_ALLOCATE|[9]|Bytes:4
14:13:25.270 (300554078)|HEAP_ALLOCATE|[9]|Bytes:0
14:13:25.270 (300599717)|HEAP_ALLOCATE|[9]|Bytes:4
14:13:25.270 (301998585)|VARIABLE_ASSIGNMENT|[9]|area|[]|0x4f890054
14:13:25.270 (302030331)|STATEMENT_EXECUTE|[11]
14:13:25.270 (302040116)|HEAP_ALLOCATE|[11]|Bytes:13
14:13:25.270 (302145657)|HEAP_ALLOCATE|[11]|Bytes:2
14:13:25.270 (302179774)|HEAP_ALLOCATE|[11]|Bytes:15
14:13:25.270 (302205706)|USER_DEBUG|[11]|DEBUG|Area after = ()

Any ideas?

3
  • does a record exist with given id. what are you getting if you run this query in developer console SELECT Id, Name FROM Dublin_Address__c WHERE Id = 'a0G5E00000AIBOKUA5' 2 days ago
  • @gaurav-sharma Yes, I have checked it a few times and also tried several records.
    – Claire
    2 days ago
  • is the real Id a PROD id and you are testing in a sandbox? As an aside, your invocable is not properly bulkified - you shouldn't be checking only for the first dublinAddressId - you need to get all of them and return an array of results.
    – cropredy
    yesterday

0

Your Answer

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

Browse other questions tagged or ask your own question.