function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suresh RaghuramSuresh Raghuram 

variable does not exist


This question is from  my practise when we update a field on the account object when there is an action on the contact object do we need to mention the particular record type of the record to make the update by a trigger.

 

Why Iam asking this is by the following code i noticed an error on the contct obj but where as not on the opportunity

 

The compiler error is AccountId does not exist.

With some modifications a part this code i tested with the opportunity obj, but there is no error.

trigger primaryPhone on Contact(before Insert){

 set<Id> ids = new set<Id>();
for(Contact cnt : Trigger.New){

ids.add(cnt.AccountId);
}
Map<Id, Account> accMapIds = new Map<Id, Account>([Select Id,Phone from Account where Id
IN: ids]);
List<Account> act = new List<Account>();
for(Contact ct : trigger.New){
if(ct.Primary__c == True){
Account acc = accMapIds.get(ct.AccountId);
acc.Phone = ct.Phone;
act.add(acc);
}
}
Update act; 
}

 

Plz share your ideas and suggestion

Thanks in advance

 

Best Answer chosen by Admin (Salesforce Developers) 
DuTomDuTom

just a hunch,  check to see if you or someone else on your org created a class called 'Contact'.

All Answers

DuTomDuTom

just a hunch,  check to see if you or someone else on your org created a class called 'Contact'.

This was selected as the best answer
Suresh RaghuramSuresh Raghuram

Thank you very much