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
AtiqahAtiqah 

Received error System.QueryException: unexpected token: s0000014qrPAAQ

Hi, I need help.
I received the below error
EXCEPTION_THROWN [22]|System.QueryException: unexpected token: s0000014qrPAAQ

Here is the Apex code
public with sharing class toApproved {
    @AuraEnabled(cacheable=true)
    //public static list<ProcessInstanceWorkitem> getItemApprove(){
    public static list<ProcessInstanceWorkitem> getItemApprove(id ActorId){
        id actorid2 = ActorId;
        system.debug('Actor: '+ActorId);
        system.debug('Actor2: '+actorid2);

        String condition = 'ActorId = '+ActorId;
        system.debug('condition: '+condition);

        string query = 'select ProcessInstance.TargetObject.name, CreatedDate, CreatedBy.name, ActorId, Actor.name from ProcessInstanceWorkitem where ' +condition + ' order by CreatedDate limit 100';
        system.debug('query: '+query);

        list<ProcessInstanceWorkitem> records = Database.query(query);
        system.debug('records '+records);

        return records;
    }
}


 
Dosbol TDosbol T
Hi there, can you please try this modified code:
 
public with sharing class toApproved {
    @AuraEnabled(cacheable=true)
    public static list<ProcessInstanceWorkitem> getItemApprove(id actorId){
        String condition = 'ActorId = :actorId';
        string query = 'select ProcessInstance.TargetObject.name, CreatedDate, CreatedBy.name, actorId, actor.name from ProcessInstanceWorkitem where ' + condition + ' order by CreatedDate limit 100';
        list<ProcessInstanceWorkitem> records = Database.query(query);
        return records;
    }
}
Thanks,
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi ,

Did you try the soql query execution which you got int debug logs for the query. Is it giving the same result? 

I guess there is some issue in adding the condition only. Can you share the soql query which you are getting from debuglog?

Thanks,
 
AtiqahAtiqah
Hi Dosbol T,

I think we cannot put code like this. It wont capture actorId from the paremeter. 
String condition = 'ActorId = :actorId';

 
AtiqahAtiqah
Hi Sai Praveen  

Below is the query from ' string query' I capture from debug log
select ProcessInstance.TargetObject.name, CreatedDate, CreatedBy.name, ActorId, Actor.name from ProcessInstanceWorkitem where ActorId = 0052s0000014qrPAAQ order by CreatedDate limit 100

I try to query above statement. This is error I received.
MALFORMED_QUERY: 
ProcessInstanceWorkitem where ActorId = 0052s0000014qrPAAQ order by CreatedDate
                                           ^
ERROR at Row:1:Column:140
unexpected token: s0000014qrPAAQ
I think it should be because of this line
String condition = 'ActorId = '+ActorId;
I change to this:
String condition = 'ActorId = \''+ActorId;
Debug:
DEBUG|query: select ProcessInstance.TargetObject.name, CreatedDate, CreatedBy.name, ActorId, Actor.name from ProcessInstanceWorkitem where ActorId = '0052s0000014qrPAAQ order by CreatedDate limit 100
Error message:
EXCEPTION_THROWN [22]|System.QueryException: line 1:186 mismatched character '<EOF>' expecting '''