1

I have the below piece of code:

 List<Job_Opening_Skill_Set__c> jobopening= [ Select id,Job_Opening__c from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()];

    Map<Id, Job_Opening_Skill_Set__c> JobopeningMap = new  Map<Id, Job_Opening_Skill_Set__c>();

    for(Job_Opening_Skill_Set__c Joskillset: jobopening){

        JobopeningMap.put(Joskillset.Job_Opening__c, Joskillset);
    }

I would like to write it as below, but it throws an error saying - first object should be concreate Sobject.

 Map<Id, Job_Opening_Skill_Set__c> JobopeningMap = new  Map<Id, Job_Opening_Skill_Set__c>();
for(List<Job_Opening_Skill_Set__c> jobopening : [ Select id,Job_Opening__c from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()]){

JobopeningMap.put(jobopening .Job_Opening__c, jobopening );
}

But this piece of code throws an error , how can resolve this error.

6
  • What line is the error in? Commented Apr 11, 2016 at 18:49
  • Initial term of the field expression must be a concrete Sobject
    – SfdcBat
    Commented Apr 11, 2016 at 18:51
  • The line, please, not the message.... Commented Apr 11, 2016 at 18:51
  • The line where I use put for the map , inside the for loop
    – SfdcBat
    Commented Apr 11, 2016 at 18:53
  • 3
    I don't see anything wrong in your code, except the space between jobopening and . Job_Opening__c Commented Apr 11, 2016 at 19:02

2 Answers 2

3

Found the problem (with a little help from an unnamed resource).

Rewrite this line

for(List<Job_Opening_Skill_Set__c> jobopening : [ Select id,Job_Opening__c from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()]){

like this

for(Job_Opening_Skill_Set__c jobopening : [ Select id,Job_Opening__c from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()]){
2

When you write

for(List<Job_Opening_Skill_Set__c> jobopening : [ Select id,Job_Opening__c
      from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()]){}

this return records in a list with 200 size which can be processed later but as you are inside trigger your code itself running in 200 chunk so as far as i know above code will not make any difference but if you still want to write you can use following code

Map<Id, Job_Opening_Skill_Set__c> JobopeningMap = new  Map<Id, Job_Opening_Skill_Set__c>();
for(List<Job_Opening_Skill_Set__c> jobopening : [ Select id,Job_Opening__c from Job_Opening_Skill_Set__c WHERE ID IN:trigger.newMap.keyset()]){

        //loop over above list of records.
        for(Job_Opening_Skill_Set__c singleJobopening : jobopening){
           JobopeningMap.put(jobopening .Job_Opening__c, singleJobopening);
        }
}
2
  • I read that if I use the way I used before , the heap size might exceed 6MB if it returns lot of records in the list
    – SfdcBat
    Commented Apr 11, 2016 at 19:42
  • 2
    as I said earlier because you are running this code in trigger, size is limited to 200 records only so you are good to go with this solution. querying data in list inside for loop is required if you are running code in a apex class :)
    – Himanshu
    Commented Apr 11, 2016 at 20:14

You must log in to answer this question.

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