function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
samdsamd 

Strange problem with user language affecting SOQL query of ProcessInstanceWorkItem

I've come across a strange issue where the user's language seems to affect the way that results are retrieved when querying the ProcessInstanceWorkItem table with SOQL.  I'm using the Apex code below inside a trigger to query the ProcessInstanceWorkItem table and create a map to see whether any of the records in the trigger are currently involved in an approval process.

 

 

 

Map<Id,Id> ProcessInstanceWorkitem_Map = new Map<Id,Id>();
for (ProcessInstanceWorkitem  P:[select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem  where ProcessInstance.Status like 'Pending' and ProcessInstance.TargetObjectId in :Trigger.newMap.keySet()])
{
   ProcessInstanceWorkitem_Map.put(P.ProcessInstance.TargetObjectId,P.Id);
} 

 

 

When this code is triggered by a user with Language = English, this code works perfectly.  However, when the same code is triggered by a user with Language = Japanese, the code doesn't work as expected and doesn't return any records even when the record is actually inside an approval process.  After investigation I discovered that that if I change the SOQL query selection criteria to have ProcessInstance.Status = 'Pending' instead of ProcessInstance.Status like 'Pending' as shown below, then the code behaves as expected.

 

 

Map<Id,Id> ProcessInstanceWorkitem_Map = new Map<Id,Id>();
for (ProcessInstanceWorkitem  P:[select Id, ProcessInstance.TargetObjectId from ProcessInstanceWorkitem  where ProcessInstance.Status = 'Pending' and ProcessInstance.TargetObjectId in :Trigger.newMap.keySet()])
{
   ProcessInstanceWorkitem_Map.put(P.ProcessInstance.TargetObjectId,P.Id);
} 

 

 

I can understand the translation workbench may affect SOQL results for certain fields, but I would expect system tables such as the ProcessInstanceWorkItem to return the same results regardless of the user's language settings. 

 

I've managed to work around this problem for now by using "=" instead of "like" inside the selection criteria, but I'd be very interested to know why this is necessary.

 

Sam

 

sfdcfoxsfdcfox

I believe that you should probably be using toLabel in order to make sure it picks up the correct value without the use of the LIKE operator. See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_tolabel.htm#kanchor578 for details.

samdsamd

Thanks for the answer, but as far as I can see this isn't quite what I'm looking for.  I'm looking for a way to query the ProcessInstanceWorkItem table that returns the same result regardless of the language setting of the user that triggers the Apex code.  As far as I know it's not even possible to enable translated values for system tables like ProcessInstanceWorkItem, so I don't know why it should return different results depending on the user language.