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
marylarmstrongmarylarmstrong 

Trigger Error: Illegal assignment from Schema

I have extremely limited developer knowledge and trying to update a field on my Lead object from a custom object.

Lead field to update: Member_Owner_Lookup__c

Custom Object Name: CustomObject__c

Custom Object Field Name: Member_Owner__c

I would like Member_Owner_Lookup__c to get updated by Member_Owner__c

 

My feeble attempt gives me the error message of "Error: Compile Error: Illegal assignment from Schema.SObjectField to Id at line 16 column 15" which is the line 'lead.Member_Owner_Lookup__c = CustomObject__c.Member_Owner__c;'

Trigger is below and any help would be greatly appreciated!

 

-----------------

 

 

trigger UpdateMemberOwner2 on Lead (before update, before insert) {
  List<Lead> leadsToUpdate = new List<Lead>();
    for (Lead lead : Trigger.new)
    {     
      if (lead.Member_Owner_Lookup__c != NULL)
      {
          // Find the sales rep for the current member owner
          List<CustomObject__c> memberowner = [select Member_Owner__c from CustomObject__c 
                                   where Name = :lead.Member_Owner_Lookup__c limit 1];
                
          // if you found one
          if (customobject.size() > 0) 
          {    
              //assign the member owner to the member owner lookup
              lead.Member_Owner_Lookup__c = CustomObject__c.Member_Owner__c;
                 leadsToUpdate.add(lead);
          
          }
       } 
          
     }
     
      // update the records
      try 
      {
           insert leadsToUpdate;
      }
      catch (DmlException dm)
      {
            
      }     
}

 

Pradeep_NavatarPradeep_Navatar

Lookup field is always associated with the id of lookuped record, so you need to give id not the name. Since Member_Owner__c gives the name of owner record not id, use Member_Owner__r.id instead of Member_Owner__c.

marylarmstrongmarylarmstrong

If i change my line to 

 

lead.Member_Owner_Lookup__c.id = CustomObject__c.Member_Owner__r.id;

 

i now get the error

Error: Compile Error: Invalid foreign key relationship: Lead.Member_Owner_Lookup__c at line 15 column 15

advise?