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
Shridhar H AShridhar H A 

Hi i created a class in my developer console.while creating object it is throwing an error"Line: 2, Column: 1 Variable does not exist: name".in ana

Best Answer chosen by Shridhar H A
sfdcMonkey.comsfdcMonkey.com
Pleasure if my answer helps you mark it best answer so it make proper solution for others and you question is remove from unsolved queries 
​thanks

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please post your code so that we can help you
Shridhar H AShridhar H A
public class Cat {
  public string name;
  public integer age;
    
    public void meow(){
        
        system.debug('hello');
    }
}

Cat c = new Cat();
c.name = 'tiger';
c.age = 15;
c.meow();
system.debug('cat name is '+c.name);
system.debug('cat age is '+c.age);

Error
Execute Anomynous Error
Line: 2, Column: 1
Variable does not exist: name
Amit Chaudhary 8Amit Chaudhary 8
Please try to update your code like below

public class Cat {
  public string name{get;set;}
  public integer age{get;set;}
    
    public void meow(){
        system.debug('hello');
    }
}


Then try below code
Cat c = new Cat();
c.name = 'tiger';
c.age = 15;
c.meow();
system.debug('cat name is '+c.name);
system.debug('cat age is '+c.age);

 
Shridhar H AShridhar H A
Hi amit,
its showing same error...
sfdcMonkey.comsfdcMonkey.com
hi Shridhar 
your code look good and its working fine in my org 
User-added image
User-added image

Maybe you're apex class is not save properly. make sure your apex class is save properly  
if you seen
* with your class name its mean your class not save yet. 
User-added image
by the [ctrl+ s ]  save your apex class 

thanks 
let me inform if it helps you 
Shridhar H AShridhar H A
yea ur ryt...thank you piyush and amit...
 
sfdcMonkey.comsfdcMonkey.com
Pleasure if my answer helps you mark it best answer so it make proper solution for others and you question is remove from unsolved queries 
​thanks
This was selected as the best answer