+ Start a Discussion
Kellee17Kellee17 

Invalid bind expression type of SOBJECT...

Please help, I am new to developing / Apex code and am trying to set up a trigger to update a picklist field (on an Activity)based on a different Object's picklist entry (User) - the ultimate aim is to set colours in a dashboard the same in two different objects - Activities and Opportunities...

 

I am getting the following error:

Error: Compile Error: Invalid bind expression type of SOBJECT:User for column of type String at line 3 column 92

 

And honestly I have no clue what I need to do to fix this...!

 

Here is my first attempt:

 

trigger UpdateDepartmentPicklist on Task (before update){
        for(Task tsk : Trigger.new){
        List<User> listUse = [Select Department_picklist__c from User where Owner_ID__c =: tsk.CreatedBy];  for
    (User use : listUse){
       Tsk.Owner_Department_Picklist__c = Use.Department_picklist__c;
            }
    update listUse;
     }  
}       

 

 

Many thanks for any assistance or tips!

Cheers,

Kelly

 

Best Answer chosen by Admin (Salesforce Developers) 
ForcepowerForcepower

Kellee,

 

Just add .Id to the CreatedBy:

 

List<User> listUse = [Select Department_picklist__c from User where Owner_ID__c =: tsk.CreatedBy.Id];

 

Best,

Ram

All Answers

ForcepowerForcepower

Kellee,

 

Just add .Id to the CreatedBy:

 

List<User> listUse = [Select Department_picklist__c from User where Owner_ID__c =: tsk.CreatedBy.Id];

 

Best,

Ram

This was selected as the best answer
Kellee17Kellee17
Thanks so much - finally I can save it! :)
Much appreciated
ForcepowerForcepower
You're very welcome, Kellee.
Best,
Ram
kotesh arudrakotesh arudra
Hi Ram here i have faced the same error while writing a trigger my requirement is i want to send a mail to record owner when record is get deletd.

trigger SendingMailToRecordOwner2 on Fan__c (after delete) {

list<Fan__c> a = [select id,CreatedBy.id from Fan__c where id in:trigger.old];
    user u = [select id,email from user where email =: a.CreatedBy.Id];
messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
    list<String> toaddress = new list<String>{'u.Email'};
email.setToAddresses(toaddress);
    email.setSubject('Records deletion alert');
email.setSubject('Account records are deleted which is created by you');
    messaging.Email[] emails = new messaging.Email[]{email};
        messaging.sendEmail(emails);

}
 
Can u pls solve it....
Thanks,
kotesh.