Symptom
Trigger or class won't compile with error "Variable does not exist: Name", where "Name" is a field on a standard object such as Account.
e.g.
trigger myAccountTrigger on Account (before insert) {
for(Account a:Trigger.New){
system.debug(a.Name);
}
}
Cause
There is a custom class with the same name as the standard object, the trigger is referring to this class and the specified attribute doesn't exist on the custom class.
e.g.
public class Account {
//test class to object conflict
}
Resolution
The thing is, we don't want our code to refer to the class - we want it to refer to the standard object.
Obviously if we knew this problem was going to come up we would never have named the class "Account" in the first place. But after the fact it could be a lot of work to change the class name (and all references to it) to something like "AccountClass".
The easy way to achieve this is by fully qualifying the references to the standard object. This is done by prefixing the object name with "Schema." No need to change the class!
e.g.
trigger myAccountTrigger on Schema.Account (before insert) {
for(Schema.Account a:Trigger.New){
system.debug(a.Name);
}
}