I have a custom object lookup Wholesaler\_\_c in Account Object. my requirement is to create a trigger, which would create a custom object record Billing\_\_c when an Opportunity is created. Billing\_\_c should take inputs from Opportunity

error thrown is:

> 
> "Apex trigger CreateBilling caused an unexpected exception, contact
>  your administrator: CreateBilling: execution of AfterInsert caused by:
>  System.SObjectException: SObject row was retrieved via SOQL without
>  querying the requested field: Account.Wholesaler\_\_r:
>  Trigger.CreateBilling: line 12, column 1"
> 
> 
> 

please help

Trigger written is:

```
trigger CreateBilling on Opportunity (after insert, after update) {
    billing__c bill = new billing__c();

    if(Trigger.isInsert == true){
        for(Opportunity opp: Trigger.new){
            if(Opp.StageName == 'Closed Won'){
                bill.Name='bill ' +opp.Name;
                bill.Opportunity__c=opp.id;
                bill.Dealer__c= opp.AccountId;
              //  Id accid =opp.AccountId;
                wholesaler__c wholesalerName = new wholesaler__c();
                wholesalerName= [SELECT Account.Wholesaler__c FROM account where id =:opp.AccountId].wholesaler__r;
                bill.Wholesaler__c= wholesalerName.name;
                system.debug('No errors observed with billing addition');
                insert bill;
            }
        }
    }

}

```