Some questions on displaying on what I can show in querying the Process.

1 - I am running into limitations on pulling in more fields in my query.

public List<ProcessInstanceStep> getSteps() {
      return [select StepStatus,  ProcessInstance.targetObject.name from ProcessInstanceStep where ProcessInstance.TargetObjectId = :T.id ];

The above successfully returns the name of the object under approval, but that isn't that helpful, since it's an auto number.

Trying to pull any other field provides errors. Example:

return [select StepStatus,  ProcessInstance.targetObject.Field__C from ProcessInstanceStep where ProcessInstance.TargetObjectId = :T.id ];  

Brings error:

No such column 'Field__c' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Why is it referencing entity Name ? Have I reached the limit in relation query? thanks

  1. I am having a error trying to query on a field on the initial object

SObject row was retrieved via SOQL without querying the requested field: Custom_Object__c.Look_up__c

I want to query on an ID in a lookup field on the object. The below does not allow me to query on a custom field on T but I think illustrates what I want to do:

    Custom_Object__c T;
    public ID TID {get; set; }
    public TravelerApprovalExtension(ApexPages.StandardController controller) {

         T = (Custom_object__C) controller.getRecord(); 
         TID = t.Look_up__c;

So I can use TID here:

public List<Look_up__c> getLups() {
      return [select name, ID, start_date__c, end_date__c , location__C  from Look_up__c where ID = :TID ];

How can I efficiently get a field as a variable on the record to use as a query parameter? thanks! Also, more generally - on a getRecord(), does one return the ID, or the (whole) record? Can't quite understand why I can't use this in my instance if I actually got the record and not just the ID-

T = (Custom_object__C) controller.getRecord(); 
         TID = t.Look_up__c;

You have three options here:

  1. Query the target object record directly (if you have only one).
  2. Create a Map<Id, SObject> to hold your target object records.
  3. Use a TYPEOF query (must be enabled through support).

Take a look at Understanding Polymorphic Keys and Relationships for a little more information on #3.

Single Record

Since you only appear to need one record, you can actually just query for it. For instance if you were looking for approvals on a specific Case record. If you are writing an extension you can access the StandardController in your constructor:

public MyExtension(ApexPages.StandardController controller)
    List<String> fieldsToQuery = new List<String> { 'Field__c' };
    if (!Test.isRunningTest()) controller.addFields(fieldsToQuery);
    // above only needed for fields not referenced on the page
    Case record = (Case)controller.getRecord();

If for some other reason you know there will be a record corresponding to the Id, your query would simply look like:

Case record = [SELECT Field__c FROM Case WHERE Id = :targetId];

Otherwise, you can query for a list and pull in the record if it's not empty:

Case record;
List<Case> candidates = [SELECT Field__c FROM Case WHERE Id = :targetId LIMIT 1];
if (!candidates.isEmpty()) record = candidates[0];


If you have multiple target object records, you can use a map.

Map<Id, Case> targetRecords = new Map<Id, Case>([
    SELECT Field FROM Case WHERE Id IN :targetIds


Polymorphic query support must be enabled to use TYPEOF queries (reference), but they are pretty useful for you in this instance once they are enabled.

List<ProcessInstanceStep> steps = [
    SELECT StepStatus,  
        TYPEOF ProcessInstance.TargetObjectId
            WHEN Case THEN Field__c
    FROM ProcessInstanceStep
    WHERE ProcessInstance.TargetObject.Type = 'Case'
  • I only need a single record - the parent of object I am using in the standard controller in the VF page, the parent of what is returned in my extension instance when I do -- T = (Custom_object__C) controller.getRecord();
    – jaw999
    Mar 7 '16 at 14:31
  • @jaw999 So just make T a property (add { get; private set; }) and then reference that instead.
    – Adrian Larson
    Mar 7 '16 at 14:34
  • I need to reference the field on T as the filter in my query and all my methods don't work. where ID =: t.lookup_field__c does nothing. Code compiles but page tells me i never returned that field. SO i guess getRecord doesn't get the record?
    – jaw999
    Mar 7 '16 at 14:47
  • @jaw999 Did you call addFields with Lookup_Field__c?
    – Adrian Larson
    Mar 7 '16 at 14:48
  • OK, progress. So I have to add fields? It is not intuitive that GetRecord doesn't return the record and its fields. It functions more like getId?
    – jaw999
    Mar 7 '16 at 14:58

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.