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
hegde_hegdekhegde_hegdek 

Trigger not able to find reference of maste object

Hello Freinds,

I have a trigger on a child object,in this trigger i need to find reference to the master object,

But i am not able to get it ,it is always null.

regards

kaushik

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Try removing the . between account and ID, e.g.

 

acc = [select Id,name from Account where Id =:smileysurprised:pp.AccountID]; 

 

 

 

All Answers

jhenningjhenning
can you post your code?
hegde_hegdekhegde_hegdek
Account is related to opportunity
Account is the master and opportunity is the child,whenever the opportunity feild status is changed i need to change the account status,so i am writing a trigger for opportunity to reference account and change status


trigger Account_Status_UPD on Opportunity (after insert,after update) {
Account acc;
Opportunity opr = new Opportunity();

for (Opportunity opp : Trigger.old) {

      acc = [select Id,name from Account where Id =:opp.Account.ID];
       //It throws an exception select itself as the opp.Account feild is null

}
}
bob_buzzardbob_buzzard

Try removing the . between account and ID, e.g.

 

acc = [select Id,name from Account where Id =:smileysurprised:pp.AccountID]; 

 

 

 

This was selected as the best answer