+ Start a Discussion

what is the use of {} Curly braces and [] Square brackets in soql query ?

whats is the use of {}, [] these to use in soql query, is there any specific use to use ?

can you pls explaine me with query exampls.

thanks in advance. 
Michael DsozaMichael Dsoza
Hi Boyapati,

Please find below the link for you query.

Hope it will help you.
Mark it as best answer. If it solves your query.
salesforce mesalesforce me
Hi Boyapati...

{ }:-
              Curly braces group elements to remove ambiguity. For example, in the clause UPDATE {TRACKING|VIEWSTAT}[,...], the curly braces indicate that the pipe shows a choice between TRACKING and VIEWSTAT after UPDATE, rather than a choice between UPDATE TRACKING and VIEWSTAT

[ ] :-
           Square brackets indicate an optional element. For example, [LIMIT rows] means that you can specify zero or one LIMIT clause. Don’t type square brackets as part of a SOQL command. Nested square brackets indicate elements that are optional and can only be used if the parent optional element is present. For example, in the clause [ORDER BY fieldOrderByList [ASC | DESC] [NULLS {FIRST | LAST}]] , ASC, DESC, or the NULLS clause cannot be used without the ORDER BY clause.
Hi Michael,

I have read that before itself but i didn't understand, so that's why i have post a question is there any one explain with examples, what is the significance use of those { }, [] brackets in SOQL Query

salesforce mesalesforce me
check this example:-[ ]:-
List classification = [
   SELECT cx_Contact_c 
   FROM cx__Contact_Classification_c 
   WHERE cx_Contact_c IN :contactIdSet 
      AND cx_Classification_Type_c NOT IN (SELECT id 
                                           FROM cx_Classification_Type_c 
                                           WHERE Name = 'blah' 
                                           OR Name = 'foo' 
                                           OR Name = 'foobar' 
                                           OR Name = 'foobar1' 
                                           OR Name = 'foobar2' 
                                           OR Name = 'foobar3') 
      OR cx_Classification_Type__c = null

check this another example:-{ }:-
List(1, 2, 3).reduceLeft{_ + _} // valid, single Function2[Int,Int] parameter

List{1, 2, 3}.reduceLeft(_ + _) // invalid, A* vararg parameter

Michael DsozaMichael Dsoza
Hi Boypati,

In SOQL syntax, {} brackets means we use any one of options(choice) mentioned in {} And [] brackets means that part is OPTIONAL in query. We can use if required else we can skip that.
See the syntax below...
SELECT fieldList [subquery][...] [TYPEOF typeOfField whenExpression[...] elseExpression END][...] FROM objectType[,...] [USING SCOPE filterScope] [WHERE conditionExpression] [WITH [DATA CATEGORY] filteringExpression] [GROUP BY {fieldGroupByList|ROLLUP (fieldSubtotalGroupByList)|CUBE (fieldSubtotalGroupByList)} [HAVING havingConditionExpression] ] [ORDER BY fieldOrderByList {ASC|DESC} [NULLS {FIRST|LAST}] ] [LIMIT numberOfRowsToReturn] [OFFSET numberOfRowsToSkip] [FOR {VIEW | REFERENCE}[,...] ] [ UPDATE {TRACKING|VIEWSTAT}[,...] ]

here {} & [] used with FOR, that means FOR keyword is an optional keyword...we can use in query or can avoid it BUT whenever we use it then we must have to pass single value (VIEW or REFERENCE) for it.

Hope it is claer to you.
Mark it as best answer. Only if you are satisfied wiht answer,