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
David JoshuaDavid Joshua 

Variable Does Not Exist. But it worked in another class

I got this "Variable Does Not Exist" problem. I have a class "FranceOperations_ReloadImpressions" : 
 
global class FranceOperations_ReloadImpressions {

    webservice static String getTotalImpressions(String id) 
    {

        France_Operations__c [] myOperation = [select id, Mecanic_operation_LU__r.id, Mecanic_operation_LU__r.Name, Vault_Adgroup__c, VaultClone_Operation_Id__c, 
            MCLU__c, MCLU1__c, MCLU2__c, MCLU3__c, MCLU4__c, MCLU5__c, MCLU6__c, MCLU7__c, MCLU8__c, MCLU9__c, MCLU10__c, 
            MCLU11__c, MCLU12__c, MCLU13__c, MCLU14__c, MCLU15__c, MCLU16__c, MCLU17__c, MCLU18__c, MCLU19__c, MCLU20__c, 
            Status__c, ID_Request_Number__c, Eligibilit_VAULT__c, Operation_ID__c from France_Operations__c where Id = :id ];
        System.debug(LoggingLevel.DEBUG, 'myOperation : ' + myOperation);
        System.debug(LoggingLevel.DEBUG, 'MCLU1__c : ' + MCLU1__c);

        if (myOperation.MCLU1__c != null || myOperation.MCLU1__c != '') {
        
            String bk = null; 
            String bk_full = null;
            String bk_extension = '--'; 
            String [] bkAfterSplit = null;

            bk_full = myOperation.MCLU1__c; 
            if (bk_full.contains(bk_extension)) {
                bkAfterSplit = bk_full.split(' -- ');
                bk = bkAfterSplit[0];
            } else {
                bk = bk_full;
            }
            
        } else {
            System.debug(LoggingLevel.DEBUG, 'MCLU1__c is empty');
        }

        // more code

}

Basically, I recover data from fields from my current page. But I get the error "Variable does not exist: MCLU1__c" since 

System.debug(LoggingLevel.DEBUG, 'MCLU1__c : ' + MCLU1__c);
But I do get myOperation with 
System.debug(LoggingLevel.DEBUG, 'myOperation : ' + myOperation);

My class is global and my webservice is static so I don't understand the range problem. I also did the same in another class and I did not get this problem... 

Any input would be greatly appreciated !

Best Answer chosen by David Joshua
David JoshuaDavid Joshua
Ok, do not look anymore. I found it. It should not be a list 
France_Operations__c [] myOperation
but just an operation as such :
France_Operations__c myOperation
I still have other errors to resolve but they are different. 
Anyway, thanks for your help ! 


 

All Answers

Raj VakatiRaj Vakati
Change your system.debug as 
 
System.debug(LoggingLevel.DEBUG, 'MCLU1__c : ' + myOperation.MCLU1__c);


because there is no variable name,e MCLU1__c whihc you need to refer from the object as myOperation.MCLU1__c
 
David JoshuaDavid Joshua
Hello Raj, 

Thanks for your quick reply. I changed my line 11 to what you gave me. But unfortunately, it did not solved my problem. the error is still 
Variable does not exist: MCLU1__c
Same at line 13 (twice) and at line 20. 

But it seems I don't recover my fields properly here. I tried that right after line 11 : 
System.debug(LoggingLevel.DEBUG, 'Operation_ID__c : ' + myOperation.Operation_ID__c);
System.debug(LoggingLevel.DEBUG, 'Vault_Adgroup__c : ' + myOperation.Vault_Adgroup__c);
And I got the same error : 
Variable does not exist: Operation_ID__c
Variable does not exist: Vault_Adgroup__c
What did I do wrong or what did I miss ? My class is global and my webservice is static. So myOperation should contain those fields I specified and it should not raise a problem of range. So in worst case, my variables should be null, not non-existant. 



 
David JoshuaDavid Joshua
Ok, do not look anymore. I found it. It should not be a list 
France_Operations__c [] myOperation
but just an operation as such :
France_Operations__c myOperation
I still have other errors to resolve but they are different. 
Anyway, thanks for your help ! 


 
This was selected as the best answer