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
Shane QuiringShane Quiring 

SOQL Statement

Hi Experts,

I really need some help here, I have a SOQL statement the grads a specific list of records and child records, but I need to edit the statement to only include those child records that are currently active, I have a check mark box called "Active" on the child record.

Here is my statment:

<soql>select LDC_Account_Number__c, meter_number__c from meter__c where ldc_account__c in (select id from ldc_account__c where opportunity__c='{!ServiceContract.opportunity__r.id}') order by ldc_account_number__c</soql>

meter__c is the child record
name of the field is Active__c

This is only my 5th SOQL statement, still learning, any assistance would be greatly appreciated. 

Thank-you
Best Answer chosen by Shane Quiring
CaptainObviousCaptainObvious
Try this:

select LDC_Account_Number__c, meter_number__c 
from meter__c 
where ldc_account__c in (select id from ldc_account__c where opportunity__c='{!ServiceContract.opportunity__r.id}') 
and active__c = true
order by ldc_account_number__c

All Answers

CaptainObviousCaptainObvious
Try this:

select LDC_Account_Number__c, meter_number__c 
from meter__c 
where ldc_account__c in (select id from ldc_account__c where opportunity__c='{!ServiceContract.opportunity__r.id}') 
and active__c = true
order by ldc_account_number__c
This was selected as the best answer
Shane QuiringShane Quiring
That worked, thank-you for your help. 

v/r
Shane