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
RJ12RJ12 

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'){
                    oppJobList.add(opp.AccountId.Name);
                }
            }
 

Help me on this. Thank you.

VamsiVamsi

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!

Regards 
Suraj Tripathi