+ Start a Discussion
Pravi_1133Pravi_1133 

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.

 

Best Answer chosen by Pravi_1133
Pravi_1133Pravi_1133
Issue resolved PRasad. thanks for the help. Issue was I had declared class name as Account. So it was causing me problem.

All Answers

Subhash GarhwalSubhash Garhwal

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

 

digamber.prasaddigamber.prasad

Hi,

 

Could you please share your trigger.

Pravi_1133Pravi_1133

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.

digamber.prasaddigamber.prasad

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.

Pravi_1133Pravi_1133
Issue resolved PRasad. thanks for the help. Issue was I had declared class name as Account. So it was causing me problem.
This was selected as the best answer