0

I've been playing around with SOQL, and I've run into an issue I don't understand. Maybe someone can shed some light for me.

I have the following code:

public static String test(String assignmentName) {

    List<Assignment__c> assignments = [SELECT Name
                     FROM Assignment__c
                     WHERE Name = :assignmentName];


    return 'hello ' + assignments[0].Month;
}

Now I get an error on the assignments[0].Month line. Month is a custom field of assignment, of type date. The error I get is 'Invalid field Month for SObject Assignment__c'. (I understand date is not a string, but this error displays before I try and convert it)

When I use a assignments[0].Name, which is a Standard Field, I get correct output.

So my question is this. How to I access this custom field Month and change it, then save it as a NEW record?

2
  • 3
    The API name of custom fields always ends with __c (whereas standard fields don't) so you need to include Month__c in the query and reference it using Month__c.
    – Keith C
    Jun 15, 2016 at 18:08
  • Not to mention that you have to include the field you want to use in your query SELECT Name, Month__c FROM ...
    – o-lexi
    Jun 15, 2016 at 18:16

1 Answer 1

4

In addition to what Keith said, you will also need to add Month__c in your query because you will get an error something like "Field not present in SOQL Query" or something like that I can't remember what it is

You must log in to answer this question.

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