+ Start a Discussion
srihari Nadendla 22srihari Nadendla 22 

Variable does not exist: OrderNumber__c


Hi all,
I am new to the trigger,Please help me for the error
I have searched all the forums but i couldnt find the answer
trigger OP on Opportunity (after insert)
{
    List<Account> acc=new List<Account>();
    for(Opportunity anu:Trigger.new)
   
    {
        if(anu.OrderNumber__c==111)
        {
            Account at=new Account();
            at.Ownership='Public';
            acc.add(at);
        }
    }
    insert acc;
}
 
Priyadarshi NayakPriyadarshi Nayak
have you created any custom field with name OrderNumber?
Arvind KumarArvind Kumar
Hi Shri,

Please you this
trigger OP on Opportunity (after insert)
{
    List<Account> acc=new List<Account>();
    for(Opportunity anu:Trigger.new)
   
    {
        if(anu.OrderNumber__c == '111' )
        {
            Account at=new Account();
            at.name = 'Test';
            at.Ownership='Public';
            acc.add(at);
        }
    }
    insert acc;
}

It will help you.

Mark a best answer , if it solves your problem.

Thanks,
Arvind Kumar
Eric PepinEric Pepin
If you haven't created OrderNumber__c on the Opportunity, you need to do so. If you are sure that you've created the Custom Field OrderNumber__c on the Opportunity, then the problem is probably permissions. Check to make sure that the Profile for the User running the code has access to the field. (Visibility = TRUE at field level for User's Profile)