You need to sign in to do that
Don't have an account?
Travis16
Unexpected Token : 'If"
I am not sure what is wrong with the Syntax but I believe I am missing something around the SOQL as I wan't getting this until I changed that.
trigger OrderUpdateDrafter 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,
(SELECT Drafter_Email__c,Drafter__c, Order__c
FROM Drafting__r
LIMIT 1)
FROM Order__c WHERE Id IN : Order__c]
}
//check if list is empty if not we will update the order with the Drafters email
if(myDrafting() > 0 && o.Drafting_Email__c = null) {
o.Drafter_Email__c == myDrafting.Drafter_Email__c;
}
}
}
trigger OrderUpdateDrafter 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,
(SELECT Drafter_Email__c,Drafter__c, Order__c
FROM Drafting__r
LIMIT 1)
FROM Order__c WHERE Id IN : Order__c]
}
//check if list is empty if not we will update the order with the Drafters email
if(myDrafting() > 0 && o.Drafting_Email__c = null) {
o.Drafter_Email__c == myDrafting.Drafter_Email__c;
}
}
}
All Answers
trigger OrderUpdateDrafter on Order__c (before insert)
{
String drafterEmail;
for (Order__c o : Trigger.new)
{
List<Drafting__c> myDrafting = new List<Drafting__c> ();
myDrafting = [SELECT Id,
(SELECT Drafter_Email__c,Drafter__c, Order__c
FROM Drafting__r
LIMIT 1)
FROM Order__c WHERE Id IN : myDrafting] ;
if(myDrafting() > 0 && o.Drafting_Email__c = null)
{
o.Drafter_Email__c == myDrafting.Drafter_Email__c;
}
}
}
I think you should write the trigger on Drafting object and then populate the email on the parent object.
trigger OrderUpdateDrafter on Order__c (before update)
{
for(Order__c o: Trigger.new){
//check if Drafting is on the order
if (o.Drafting_Kingspan__c = true){
//get 1 drafting record as the assigned drafter should be the same across all drafting records for the order
List<Drafting__c> myDrafting = new List<Drafting> ();
myDrafting = [SELECT Id,Drafter_Email__c,Drafter__c, Order__c
FROM Drafting__r
//make sure that my drafting records are from my trigger.new reocrd
WHERE Order__c = o.Id];
//check list to make sure values are there and if the order needs the drafter email updated
if(myDrafting() > 0 && o.Drafting_Email__c = null){
//update the drafters email address if needed
o.Drafter_Email__c == myDrafting.Drafter_Email__c;
}
}
}
}
Sorry, if I am confusing you.