You need to sign in to do that
Don't have an account?
imAkashGarg
inner join in SOQL
I need to add a inner join to my querry to fetch the master records based on the child records.
My Code:
order = [select name,id,Order_Printed__c, Order_Status__c, (select name, ActiveFlag__c,Item_Supplier__c,
from Order_Lines__r where (ActiveFlag__c = True AND item_Supplier__c = 'business') )
from Order__c where Order_Status__c = 'Ready for dispatch' AND Order_Printed__c = False];
This code fetches the order even if no matching Order_line is found. but i want only orders with matching orderlines.
Thanks in advance
It can be written like
order = [select name,id,Order_Printed__c, Order_Status__c, (select name, ActiveFlag__c,Item_Supplier__c,
from Order_Lines__r where (ActiveFlag__c = True AND item_Supplier__c = 'business') )
from Order__c where Order_Status__c = 'Ready for dispatch' AND Order_Printed__c = False and id in (select order__c
from Order_Lines__c where (ActiveFlag__c = True AND item_Supplier__c = 'business'))];
All Answers
Try using following code to get matched Order Line:
Let me know if you face any issues in it.
Regards,
Lakshman
you can just loop through the result see where the line item list size is zero and neglact the record.
It can be written like
order = [select name,id,Order_Printed__c, Order_Status__c, (select name, ActiveFlag__c,Item_Supplier__c,
from Order_Lines__r where (ActiveFlag__c = True AND item_Supplier__c = 'business') )
from Order__c where Order_Status__c = 'Ready for dispatch' AND Order_Printed__c = False and id in (select order__c
from Order_Lines__c where (ActiveFlag__c = True AND item_Supplier__c = 'business'))];
Sam just optimized the code.
Cheers Sam :)
Regards,
Lakshman
I think query in where clause wont work in salesforce.
Well, it (subquery in where clause in SOQL) perfectly works in salesforce, I have used it multiple times.
Sam can you just give me exact syntax for some object
because when I tried it didnt work.
well yeah
Account[] ac = [select id, name from Account where id in (select AccountId from Contact)];
this one is very basic, it gives those account which have atleast one contact. You can make up on it.
Regards
Thanks Sam
Thanks Sam,
akash and pankaj
welcome fellas............