You need to sign in to do that
Don't have an account?
Loop variable must be of type SOBJECT:Account
Hi,
I am facing following problem. This is not my code, I just copy pasted this from Developers guide.
Code:
Trigger t on Account (after insert) {
for (Account a : Trigger.new) {
// Iterate over each sObject
}
WHERE AccountId IN :Trigger.new];
}
Note only this, If I want to access "a.Name" it is giving me "Name" variable doesn't exist. I facing these problems recently.
I have created few triggers previously, if I just open in edit and try to save it is throwing error.
I would like to know here, is there any change in variable declaration and new changes introduced by SFDC.
Please help me , am not able write any simple trigger.
Your help is much appreciated.
All Answers
Hi Pravi,
I think there is no change in variable declaration
In your trigger i didn't understand your where close, so i think you need to correct it also
you can simply use variables like
for (Account acc : Trigger.new) {
//If you want assign value
acc.Name = something;
}
Thanks
Hit the Kudos button (star) and Mark as solution if it post helps you
Hi,
Could you please share your trigger.
Thanks for your quick reply.
I was trying to update a field in account after insert event.
My Trigger code:
trigger myTrgr on Account (After insert) {
List<Account> LstAcc1 = new List<Account> ();
for (Account A : trigger.new){
A.AnnualRevenue=10000;
LstAcc1.add(A);
}
update LstAcc1;
}
As usual, I am getting following error,
Error: Compile Error: Variable does not exist: AnnualRevenue at line 5 column 5
I just copy pasted field name from detail page. Please help me. Thanks in advance.
Hi,
Sorry for late reply, was on Paternity leave.
Is it fixed for you or not? I tried running same trigger and it's not giving the error said by you. Rather, you can't update the same record in trigger after insert event.
Let me know if you have any question.