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
Admin User 3354Admin User 3354 

Error in Accessing Standard & custom fields of Opportunity

I am not able to access standard & custom fields of Opportunity Object in my apex classes. It gives me error "Variable does not exist" even for standard fields of Opportunity.
David Holland 6David Holland 6
Could you possibly post your code so we can see whats going on? Many thanks :)
Tarun_KhandelwalTarun_Khandelwal
Hi,

Please copy your code here for better understanding
 
Admin User 3354Admin User 3354
@isTest

public class TestAttendanceUpdateTaxi
{
  private  static testMethod void TestinsertAttendance()
    {
        //Fetching Record Type for Taxi Obj
         RecordType rt = [SELECT id, Name FROM RecordType WHERE SobjectType='Taxi__c' AND Name='Sherbet'];
        Account account = new Account();
        account.Name= 'Test Account';
        insert account;
/*
    //Insering into Opportunity
    Opportunity opp = new Opportunity();
        opp.Name = 'hello';
  */      
        
       //Inserting Record for Taxi Obj
        Taxi__c OTaxi = new Taxi__c();
        OTaxi.recordTypeId=rt.id;
        OTaxi.Name = 'Tx912';
        OTaxi.Company__c = '001q000000JwBJT';
        OTaxi.Last_Attended_Date__c = System.today();
        insert OTaxi;
        
        //Retrive inserted Taxi
        OTaxi = [select Name from Taxi__c where Id =: OTaxi.Id];
        System.debug('Taxi Registration No :'+ OTaxi.Name);
        
        //Inserting record for Attendance Object
       Driver_Payment__c OAttendance = new Driver_Payment__c();
       OAttendance.Campaign__c = '006q0000005VjjN'; //[SELECT Id FROM Opportunity WHERE Name = 'testbrand' LIMIT 1].Id;
       OAttendance.Company_Name__c = account.Id; //'001q000000JwBJT';
       OAttendance.Taxi_ID__c  = OTaxi.Id;
       OAttendance.Attended_Date__c = System.today();
       OAttendance.Update_current_receipt_campaign__c = True;
       OAttendance.Update_current_Superside_Livery_Campaign__c = True;
     //  OAttendance.Update_current_Tip_seat_campaign__c = True;
       
       insert OAttendance;
        System.debug('Inserted values in Attendance obj');
       //updating attendance
    
        OAttendance.Update_current_Tip_seat_campaign__c = True;
       update OAttendance;
        
        //Assert
       Taxi__c ObjTaxi = [select Last_Attended_Date__c from Taxi__c where Name = 'Tx912' and Taxi__c.Company__c =: account.Id /*'001q000000JwBJT'*/ limit 1];
      System.assertEquals(OAttendance.Attended_Date__c , ObjTaxi.Last_Attended_Date__c);
    }
}
Admin User 3354Admin User 3354
I have put my code of test class. Which is working fine. But for Opportunity  which i have commented in my code , for that part I am gettin error
 
Admin User 3354Admin User 3354
I am getting error "Variable does not exist". This error is only for Opportunity fields.
Tarun_KhandelwalTarun_Khandelwal
Hi,

Please check field level security and Permission for Opportunity object for current profile.
Admin User 3354Admin User 3354
Yes ,I have already gone through it, but still I am facing the same problem. I am facing this error in sandbox. because of which I really cant deploy anything to my production. My sandbox have all admin permission.