I am creating an Apex Class using eclipse and trying to use a field.

I have created a custom object called Credit_Insurance__c and a custom field named Credit_Insurance_Status_c.

When I try to use the field in my class, I get an error saying that the variable doesn't exist.

I have tried the field api name and object_api_name.field_api_name. I'm sure it's name syntax.

  • 3
    could you add line, how you are using this field? – Ilya Lepesh May 13 '16 at 17:19

If you want to simply get metadata for the field, there are a few different pieces of information you can get.

Schema.SObjectField myCustomField = Credit_Insurance__c.Credit_Insurance_Status__c;
DescribeFieldResult describe = myCustomField.getDescribe();

If you want to get data, you need a Credit_Insurance__c record to get the data from.

Credit_Insurance__c record = new Credit_Insurance__c(); // instantiate as desired
String status1 = record.Credit_Insurance_Status__c;
String status2 = (String)record.get(myCustomField));
String status3 = (String)record.get('Credit_Insurance_Status__c');

With a checkbox, it would be:

if (record.Validation1__c) { /* do stuff */ }

It looks to me that you simply forgot the __c for customfields and -objects. You need to access your object like this:

Credit_Insurance__c myCi = new Credit_Insurance__c;

// you still need to query for the object or set initial values and insert it later, if you create a new one

if (myCi.Credit_Insurance_Status__c == true ) {
  // your logic here

be aware, that your snipped with one single = wont work, because it trys to assign the value to the field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.