I am new to Salesforce . I am having a bit of problem wriiting a trigger, any help would be appriciated.
I want to Write a trigger that will set the name of an Opportunity record when it is created and when the fields below are updated. The opportunity name should contain the following, each separated by a space: Account Name,Owner Last Name, Opportunity Close Date.
trigger SetOpportunityName on Opportunity (before insert, before update) {
for (Opportunity op: Trigger.new) {
op.Name = op.Account.Name+' '+Op.Owner.LastName+' '+op.ClosedDate;
system.debug('*****************************' + op.Name);
}
But I am getting op.Account.Name and Op.Owner.LastName values as null.
I know there is a mistake, Please guide me.