You need to sign in to do that
Don't have an account?

get Account Name from Contact Object
Hi,
I want to get the Account.Name from the Account object from the Contact (before insert) Trigger.
1. I fill Contact details
2. I select the Account
Then I fire my trigger. My trigger is for Contact object.
I have the Contact object details
Contact[] cont = Trigger.new;
I tired to access the Account.Name related to this Contact by
cont.Account.NameBut it returns NULL.
Please Help me.
Thanks in advance
Basically if you want the account associated with the contact. Then you can do this
Contact[] cont =[Select name, Account.Name from contact where id in: Trigger.new];
After that use EX : cont[0].Account.Name
Regards,
Manjunath
All Answers
You will not have option to access lookup fileds value from the Trigger.new.
You need to query to get that.
Regards,
Manjunath
Ohh... OK But, with what values I can query it? Because at the moment I only have details of the Contact object. User can select any Account when adding the Contact record. How can I specifically select the Account that the user selects?
Could you please help me on this as well? Thankyou.
Basically if you want the account associated with the contact. Then you can do this
Contact[] cont =[Select name, Account.Name from contact where id in: Trigger.new];
After that use EX : cont[0].Account.Name
Regards,
Manjunath
Hi Manjunath. Thank you for response.
IT IS WORKING with your code.
Thank you again for helping me.