You need to sign in to do that
Don't have an account?
Danny Hartley
Help with cross-object trigger
Hello Everyone,
I am trying to create a trigger that updates a picklist field on the Account object whenever that account has a Par_Level__Line__c created for a particular family of products. The custom object, Par_Level_Lines__c, has a lookup relationship to the Account object. The custom field on account is named Allocation_Review_Week__c. Here is the trigger code I have written so far:
trigger AllocationReviewWeek on Par_Level_Lines__c (after insert){
List <ID> AccountsID = new List<ID>();
for(Par_Level_Lines__c o : Trigger.new){
if(o.Product_Family__c = 'Our Products' && Par_Level_Lines__c.Account__c.Allocation_Review_Week__c == null){
AccountsID.add(Par_Level_Lines__c.Account__c.ID);
}
}
List<Accounts> AcctUpdate = [Select id, Par_Level_Lines__c.Account__c FROM Account Where id in : AccountsID];
for(integer i = 0 ; i < AcctUpdate.size(); i++){
AcctUpdate[i].Par_Level_Lines__c.Account__c.Allocation_Review_Week__c = "1";
}
update AcctUpdate;
}
I keep hitting a compiler error on the 8th line of code. Thanks in advance for any help.
I am trying to create a trigger that updates a picklist field on the Account object whenever that account has a Par_Level__Line__c created for a particular family of products. The custom object, Par_Level_Lines__c, has a lookup relationship to the Account object. The custom field on account is named Allocation_Review_Week__c. Here is the trigger code I have written so far:
trigger AllocationReviewWeek on Par_Level_Lines__c (after insert){
List <ID> AccountsID = new List<ID>();
for(Par_Level_Lines__c o : Trigger.new){
if(o.Product_Family__c = 'Our Products' && Par_Level_Lines__c.Account__c.Allocation_Review_Week__c == null){
AccountsID.add(Par_Level_Lines__c.Account__c.ID);
}
}
List<Accounts> AcctUpdate = [Select id, Par_Level_Lines__c.Account__c FROM Account Where id in : AccountsID];
for(integer i = 0 ; i < AcctUpdate.size(); i++){
AcctUpdate[i].Par_Level_Lines__c.Account__c.Allocation_Review_Week__c = "1";
}
update AcctUpdate;
}
I keep hitting a compiler error on the 8th line of code. Thanks in advance for any help.
Please use simple code snippet as below, It would definately help you :)
I am assuming "Allocation_Review_Week__c" is text field, that's why we have given value : - "1"
If it is number field then please remove quote, i.e 1
Mark as best answer, if it works
Thanks
All Answers
try the below code :
let me know the outcomes .
Regards,
Please use simple code snippet as below, It would definately help you :)
I am assuming "Allocation_Review_Week__c" is text field, that's why we have given value : - "1"
If it is number field then please remove quote, i.e 1
Mark as best answer, if it works
Thanks
Does your issue get solved ? please let me know
Thanks
trigger AllocationReviewWeek on Par_Level_Lines__c (after insert){
List <ID> AccountsID = new List<ID>();
for(Par_Level_Lines__c o : Trigger.new){
if(o.Product_Family__c = 'Our Products' && Par_Level_Lines__c.Account__c.Allocation_Review_Week__c == null){
AccountsID.add(Par_Level_Lines__c.Account__c.ID);
}
}
List<Accounts> AcctUpdate = [Select id, Allocation_Review_Week__c FROM Account Where id in : AccountsID];
for(integer i = 0 ; i < AcctUpdate.size(); i++){
AcctUpdate[i].Allocation_Review_Week__c = "1";
}
update AcctUpdate;
}
Error: Compile Error: line 10:54 no viable alternative at character '"' at line 10 column 54
After changing the quotations to apostrophes I received this error:
Error: Compile Error: line 10:54 no viable alternative at character '"' at line 10 column 54
Error: Compile Error: Invalid type: Accounts at line 8 column 10
Thanks, that did what I needed!
@Danny, Please feel free to contact me in case of any issue on gmail : - rajatzmaheshwari@gmail.com
Thanks