7

I was recently looking at wrapper classes and googled the following page...http://wiki.developerforce.com/page/Wrapper_Class

While I understood wrapper classes, I was baffled by the following...

public List<cContact> getContacts() {

    if(contactList == null) {

        contactList = new List<cContact>();

        for(Contact c: [select Id, Name, Email, Phone from Contact limit 10]) {

            // As each contact is processed we create a new cContact object and add it to the contactList
            contactList.add(new cContact(c));
        }
    }
    return contactList;
}

and in particular...

for(Contact c: [select Id, Name, Email, Phone from Contact limit 10]) { ... }

What is that select and from? Where can I look at more info for this in the foreach?

I know about LINQ and the select, from, where, etc.... but I never seen _this_ syntax before. What is it and how do I research more about this syntax?

Artless
  • 4,522
  • 1
  • 25
  • 40
Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58
  • 4
    I don't think it is C#... "In Apex and Visualforce this type of class ..." - looks like name of the language is "Apex" according to your link... (re-tagged the question) – Alexei Levenkov Aug 22 '13 at 07:25
  • Yep, looks like: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_loops_for_SOQL.htm – jAC Aug 22 '13 at 07:29
  • 2
    Yeah i gues so it is [Apex](http://wiki.developerforce.com/page/From_SQL_to_SOQL) *There’s Apex, a language that superficially looks like C#, but requires a completely different set of design patterns....* and guess the right term for it is `SOQL(Salesforce Object Query Language)` – V4Vendetta Aug 22 '13 at 07:29
  • 1
    Looks like java's iterator loop – Sriram Sakthivel Aug 22 '13 at 07:30
  • Yeah, I was trying to find the language. But I seen the...{ get; set; } which I only knew about from C#, and I thought was kind of MS's. – Christopher Rucinski Aug 22 '13 at 07:30

2 Answers2

2

I don't like leaving questions unanswered...

For the particular question raised ... http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_loops_for_SOQL.htm

For Salesforce Object Query Language (SOQL) in general - which the select/from in square brackets is know as ... http://www.salesforce.com/us/developer/docs/soql_sosl/salesforce_soql_sosl.pdf

For the APEX Language in general, since that is the language that happens to look very C#-ish (more examples of question raised)... http://wiki.developerforce.com/page/Apex_Code:_The_World's_First_On-Demand_Programming_Language

Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58
1

There is also this Cheat-sheet that shows more about that type of syntax, along with other ways of using APEX. Check it out here

The For loop..."defines a loop. The three types of for loops are: iteration using a variable, iteration over a list, and iteration over a query.

Example:

String s = 'Acme'; 
for (Account a : [SELECT Id, Name, FROM account WHERE Name LIKE :(s+'%')]) 
{
    // Your code
}

That syntax is for the above mentioned SOQL, and it is slightly different from C#'s own layout of the LINQ syntax, although they are very similar!