function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sparun1607sparun1607 

Compile Error: Initial term of field expression must be a concrete SObject

Hi All,

 

I am new to salesforce, currenlty i facing an compiler error : Initial term of field expression must be a concrete SObject at bolded line. 

I'm not able to understand why i getting this error. Since i need to add KEY1__C value to the list.

kindly let me know if my usage of the code is wrong.

 

List<String> pereTechniqueParams = new List<String>();


for (String key1: [SELECT KEY1__c FROM Parameters__c WHERE TYPE__c = 'PERE_TECHNIQUE']){
pereTechniqueParams.add(key1.KEY1__c);  // Compile Error: Initial term of field expression must be a concrete SObject: String at line 30 column 41
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jayjaysjayjays

Hi,

 

the SOQL query will return a list of sObjects, in this case a list of Parameters__c, so key1 is of type Parameter__c.

 

List<String> pereTechniqueParams = new List<String>();


for (Parameters__c key1: [SELECT KEY1__c FROM Parameters__c WHERE TYPE__c = 'PERE_TECHNIQUE']){
pereTechniqueParams.add(key1.KEY1__c); 
}

 

Thanks,

James.

All Answers

jayjaysjayjays

Hi,

 

the SOQL query will return a list of sObjects, in this case a list of Parameters__c, so key1 is of type Parameter__c.

 

List<String> pereTechniqueParams = new List<String>();


for (Parameters__c key1: [SELECT KEY1__c FROM Parameters__c WHERE TYPE__c = 'PERE_TECHNIQUE']){
pereTechniqueParams.add(key1.KEY1__c); 
}

 

Thanks,

James.

This was selected as the best answer
sparun1607sparun1607
Thanks James