I have to perform below logic to update opportunity status based on opportunity's Account's trial__c field on insert of opportunity.
For(Opportunity opp : trigger.new)
{
If(opp.Account.trial__c == 'service')
{
opp.status__c = 'Closed';
}
}
however trigger.new doesnt contain related object field so we will need to query it from opportunity and for that we would need id. So above logic cannot be performed in before trigger of opprotunity and doing this logic in after trigger of opportunity wont be best practice as we will be updating field of opportunity record in opportunity after trigger.
What can be the best way to implement this functionality.