You need to sign in to do that
Don't have an account?
Travis16
SOQL Child Record List
I am writing a trigger that will Query Child records of a custom object and return 1 value. As there should only be 1 child record we need to pull back the email address of the assigned Drafter. Once we have the Drafters email we will use that in process builder to send out emails when a change is made if it affects the Department. I think there is something wrong with my SOQL as I am getting an error around the expected ; and got o.id. I am not sure what I did wrong. a fresh set of Eyes would help. Thanks
Trigger (Not Complete)
trigger updateDrafterEmail on Order__c (before insert) {
String drafterEmail;
for (Order__c o : Trigger.new){
//Get all the Drafting records in a list where drafting is on the order
List<Drafting> myDrafting = new List<Drafting> {
myDrafting = [SELECT Id,
SAP_Order__c,
Drafting_Kingspan__c,
Drafting_Email__c,
WHERE Id
In
(SELECT Drafter__c,
Drafter_Email__c
FROM Drafting__r
WHERE Drafter__c != null )
Limit 1;
}
//check if list is empty if not we will update the order with the Drafters email
if(myDrafting > 0 && o.Drafter_Email__c != null){
}
}
}
Trigger (Not Complete)
trigger updateDrafterEmail on Order__c (before insert) {
String drafterEmail;
for (Order__c o : Trigger.new){
//Get all the Drafting records in a list where drafting is on the order
List<Drafting> myDrafting = new List<Drafting> {
myDrafting = [SELECT Id,
SAP_Order__c,
Drafting_Kingspan__c,
Drafting_Email__c,
WHERE Id
In
(SELECT Drafter__c,
Drafter_Email__c
FROM Drafting__r
WHERE Drafter__c != null )
Limit 1;
}
//check if list is empty if not we will update the order with the Drafters email
if(myDrafting > 0 && o.Drafter_Email__c != null){
}
}
}
The syntax for child query is In the above query Account is the parent obejct and contacts are child object.
In your query you do not have From portion for your parent object
Hope this helps.
All Answers
The syntax for child query is In the above query Account is the parent obejct and contacts are child object.
In your query you do not have From portion for your parent object
Hope this helps.
myDrafting = [SELECT Id
FROM = Order__r
WHERE Id
IN (SELECT Drafter__c, Drafter_Email__c, Order__c
FROM Drafting__r
WHERE Drafting__c != null)
LIMIT 1;]
If Order is you parent object and drafting is your child object then your query should be
Please note that in your queyr ID IN (SUB QUERY) wont work because ID is expecting reference of Order__c object and your subquery is returning Drafting__c object.
FROM Order__c WHERE Id IN =: Order__c
myDrafting = [SELECT Id,
(SELECT Drafter_Email__c,Drafter__c, Order__c
FROM Drafting__r
LIMIT 1)
FROM Order__c WHERE Id IN : Order__c]
Id is the only field on need
CHILD OBJECT - Drafting__c (Custom Object with Email address)
Drafter_Email__c and Order__c (Which is my Order__c Id)
For my Order within my FOR loop I need to pull back 1 Drafting Record to get an email address for the Drafter that is assigned to this record. With that email address I need to update my Parent Obejct Order__c with the Email address.
I hope this helps answer your question.