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
Tai Rahman 10Tai Rahman 10 

Help with SOQL Query in Workbench

Hello,

We have a custom object (Activation_Step__c ) that tracks the necessary steps (ex: Inventory_Status__c) required to complete an Opportunity.

I am trying to find the completion dates for each of the required steps but so far coming empty handed as I'm getting the overall LastModifedDate for the Object as opposed to the individual steps themselves:

select Opportunity__c, id, CreatedDate, Inventory_Status__c, Contact_Status__c, Payment_Status__c, Contract_Status__c, Activation_DateTime__c, LastModifiedDate   
from Activation_Step__c  

I am new to SOQL, but have decent experience with MSSQL, and theoretically given the fields above, it would have been easy select top 1 subselects. 

Any advice on how to achieve this using SOQL via Workbench?

Thank you in advance! 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Tai,

In case if there are separate date fields to each step then you can simply mention them as the fields to be fetched and you would be getting the field values.

If that is not the scenario can you mention how are you storing the dates so that we can check further and respond back.

Looking forward to your response.

Thanks.
Tai Rahman 10Tai Rahman 10
Hi Anutej,

Thanks for getting back to me! So basically what I'm trying to do is get the earliest CreatedDate for each of the status fields from the Activation_Step__History.

For example, If I ran the query above, it would return about 150-200 rows for each unique Opportunity. What I need is the earliest creation date for say Inventory_Status__c; in MSSQL I could write: 

(select top 1 CreatedDate
from Activation_Step__History 
Activation_Step__c.ParentId = Activation_Step__History.ParentId
where Field = Inventory_Status__c
and NewValue = 'Step Complete!' 
Order by CreatedDate asc) 


So was just hoping I could get some help on how to achieve the same thing using SOQL.

Thanks! 
Malik WaqasMalik Waqas
Writing SOQL & SOSL in workbench best jigsaw machine (https://bestjigsawguide.com)
To execute SOQL or SOSL queries, go to queries tab & click on query type you want to execute and select the object, fields you want to query and also you can filter results by using filter result by section. Query will automatically come based on your selection