• marylarmstrong
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

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)
      {
            
      }     
}

 

This trigger works just fine in my sandbox, but doesn't pass the test so I can upload into production. Can anyone please help?

 

trigger UpdateCustomeObject_Trigger on Lead (before update) {
//This trigger will associate a Custom Object record with the contact and opportunity associated to the 
//lead after it has been converted.
//The Custom Object is associated to an opportunity only if an opportunity record exist on the Lead.
    for (Integer i = 0; i < Trigger.new.size(); i++){
        if (Trigger.new[i].IsConverted == true && Trigger.old[i].isConverted == false){
            Set<Id> leadIds = new Set<Id>();
            for (Lead lead : Trigger.new) 
                leadIds.add(lead.Id);
            
            Map<Id, CustomObject__c> entries = new Map<Id, CustomObject__c>([select Contact__c, Opportunity__c, Account__c, Lead__c from CustomObject__c where lead__c in :leadIds]);        
            if(!Trigger.new.isEmpty()) {
                for (Lead lead : Trigger.new)  {
                    for (CustomObject__c CustomObject : entries.values()) {
                        if (CustomObject.Lead__c == lead.Id) {
                            CustomObject.contact__c = lead.ConvertedContactId;
                            CustomObject.opportunity__c = lead.ConvertedOpportunityId;
                            CustomObject.account__c = lead.ConvertedAccountId;
                            update CustomObject;
                            
                        }
                    }
                }
            }
        }
    }

}

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)
      {
            
      }     
}