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
    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 Aug 4 '17 at 12:57
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

| improve this answer | |
  • 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 – Akash kumar Aug 4 '17 at 9:21
  • 2
    The API names of custom field should also end with __c – Ankita Aug 4 '17 at 9:23
  • Add a screenshot of the fields with the API name – Ankita Aug 4 '17 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 Aug 4 '17 at 9:34
  • 1
    But ensure to give proper API name of the fields. – Ankita Aug 4 '17 at 10:27

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.