0

Error: Compile Error: Invalid type: Schema.Position at line 10 column 12

I am new to salesforce and following is my code :

public class c1{
    List <Position__c> pstn = new List<Position__c>();


    public List<Position__c> getpstn(){
    return pstn;
    }

    public PageReference ITReport_pstn(){
    pstn = [select Name, Type, Industry, Phone from Position where Type = 'IT Report'];
    return ITReports;
    }

    public PageReference NonITReport_pstn(){
    pstn = [select Name, Type, Industry, Phone from Position where Type = 'NonIT Report'];
    return NonITReports;
    }

enter image description here

this is the screenshot for custom field

1
  • 1
    I've edited your question for you this time to include your screenshot. For the future, you can edit your own questions (and answers) by clicking the "edit" link that sits right under the tags for your question. It doesn't really look like a link, but it is.
    – Derek F
    Commented Aug 4, 2017 at 12:57

1 Answer 1

7

Position is a custom object. The API name of custom object always end with __c. In your SOQL, you gave incorrect API name of the object, and therefore a compiler error was thrown

Updated code:

public class c1{
    List <Position__c> pstn = new List<Position__c>();

    public List<Position__c> getpstn(){
        return pstn;
    }

    public PageReference ITReport_pstn(){
        pstn = [select Name, Type, Industry, Phone from Position__c where Type = 'IT Report'];
        return ITReports;
    }

    public PageReference NonITReport_pstn(){
        pstn = [select Name, Type, Industry, Phone from Position__c where Type = 'NonIT Report'];
        return NonITReports;
    }
}

Refer Custom object in Salesforce

8
  • ya i know that API name should always ends with__c but this time showing this error Error: Compile Error: select Name, Type, Industry, Phone from Position__c ^ ERROR at Row:1:Column:14 No such column 'Type' on entity 'Position__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 16 Commented Aug 4, 2017 at 9:21
  • 2
    The API names of custom field should also end with __c
    – Ankita
    Commented Aug 4, 2017 at 9:23
  • Add a screenshot of the fields with the API name
    – Ankita
    Commented Aug 4, 2017 at 9:27
  • 1
    FYI, for a custom object, most field names also end in __c e.g. Type__c. There is a lot of training material such as Data Modeling that you should go through to learn the basics, otherwise you will always be guessing as you work.
    – Keith C
    Commented Aug 4, 2017 at 9:34
  • 1
    But ensure to give proper API name of the fields.
    – Ankita
    Commented Aug 4, 2017 at 10:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .