+ Start a Discussion
SFDC Coder 8SFDC Coder 8 

Error in SOQL Query_Trigger

Hi All,
I have written trigger as below
Trigger TskTrigger on Task (after inert){
 List<Obj1__c> ls=[Select Id,Fld1__c,Fld2__c from Obj1__c];
//Some code
//Some code
if(Trigger.isInsert){

    List<Task> ts = new List <Task>();

        for(Task Tsk : trigger.new){
    
        Task c = new Task(Fld1__c=ls.Fld__c,Fld2__c=ls.Fld2__c);
}
But, I am getting error as " Initial term of field expression must be a concrete SObject: List<Obj1__c> at line  column "
What is wrong here?
Please help

Thanks in Advance
Best Answer chosen by SFDC Coder 8
sandeep reddy 37sandeep reddy 37
you can not  assain list of values to single field so 
use this coad

Trigger TskTrigger on Task (after inert){
 List<Obj1__c> ls=[Select Id,Fld1__c,Fld2__c from Obj1__c];
//Some code
//Some code
if(Trigger.isInsert){

    List<Task> ts = new List <Task>();

        for(Task Tsk : trigger.new){
for(obj1__c b:ls){
    
        Task c = new Task(Fld1__c=b.Fld__c,Fld2__c=b.Fld2__c);
}
insert tsk;
}
}
 

All Answers

Rowallim TechnologyRowallim Technology
Hi SFDC
You have a spelling mistake in line 1(after inert). It should be (after insert).
Hope it will help You.
Please mark it as best answer.
Thanks
SFDC Coder 8SFDC Coder 8
Hi Rowallim,
In my devloper org its correct
Still, I am getting same error
Rowallim TechnologyRowallim Technology
Hi SFDC
there is error in the Last line (Task c = new Task(Fld1__c=ls.Fld__c,Fld2__c=ls.Fld2__c); It should be (Task c = new Task(Fld1__c=ts.Fld__c,Fld2__c=ts.Fld2__c);
Hope this will help you.
Please mark it as best answer.
Thanks
SFDC Coder 8SFDC Coder 8
I want to map Obj1 fields to Task
Thats why I gave Fld1__c=ls.Fld__c
My requirement is like this
Rowallim TechnologyRowallim Technology
Hi SFDC Coder 8
Use this code and let me know if it helps.
Trigger TskTrigger on Task (after insert){
 List<Obj1__c> ls=[Select Id,Fld1__c,Fld2__c from Obj1__c];
//Some code
//Some code
if(Trigger.isInsert){

    List<Task> ts = new List <Task>();

        for(Task Tsk : trigger.new){
    
        Task c = new Task;   
            c.Fld1__c = ls.Fld__c;
           c.Fld2__c  = ls.Fld2__c;
}
         insert c;
}

Thanks
SFDC Coder 8SFDC Coder 8
Hi,
It is not working
SFDC Coder 8SFDC Coder 8
Its giving error as "Variablels.Fld1__c" doesnt exist
Rowallim TechnologyRowallim Technology
Hi
Could you post your complete code. Because i'm not seeing anything that can have error.
Thanks
Rowallim TechnologyRowallim Technology
Hi
The error you got itself says that you don't have "Variablels.Fld1__c" .
sandeep reddy 37sandeep reddy 37
you can not  assain list of values to single field so 
use this coad

Trigger TskTrigger on Task (after inert){
 List<Obj1__c> ls=[Select Id,Fld1__c,Fld2__c from Obj1__c];
//Some code
//Some code
if(Trigger.isInsert){

    List<Task> ts = new List <Task>();

        for(Task Tsk : trigger.new){
for(obj1__c b:ls){
    
        Task c = new Task(Fld1__c=b.Fld__c,Fld2__c=b.Fld2__c);
}
insert tsk;
}
}
 
This was selected as the best answer