+ Start a Discussion

Get Account Name in Opportunity

I'm new to SF Developement. I'm trying to get Account Name in the Opportunity for some scenario.
I'm getting Null value when I'm trying this code

for(Opportunity opp:trigger.New){
                if(opp.Quote_Category__c != 'Choose One'){

Help me on this. Thank you.


replace opp.AccountId.Name with -> opp.Account.Name

Hope this helps...!!

Mark as best answer if the above helps ..!!

David @ ConfigeroDavid @ Configero
First, you have to know in a trigger it will only provide the fields on that record itself.  If you need related record field data, such as a lookup or master/detail relationship, then you have to query for that data via SOQL.

If you don't need a lot of data from other related fields and want to avoid a SOQL query, another trick is to make a formula field.  You could make a formula field on the Opportunity called 'Account Name' and it's value would be 'Account.Name', then in your trigger you could reference opp.Account_Name__c without doing any additional SOQL queries.

Please mark this answer as correct if it helped you.
Suraj Tripathi 47Suraj Tripathi 47
Hi RJ12,

You have to change AccountId.Name to Account.Name like this-:
Replace this line oppJobList.add(opp.AccountId.Name);
with this code oppJobList.add(opp.Account.Name);

If you find your Solution then mark this as the best answer. 

Thank you!

Suraj Tripathi