• mike.rametta.ax1705
  • NEWBIE
  • 0 Points
  • Member since 2013

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

I have a trigger I want to update a related field in the Lead Object To Store the Related Contact based on an email match. 

 

trigger LeadTrigger on Lead (before insert, before update, after insert, after update) 
{	
	if(Trigger.isBefore)
	{
        List<String> leadEmails = new List<String>();
    	for(Lead lead:Trigger.new)
    	{
        leadEmails.add(lead.Email);
    	}

    	List<Contact> contacts = [SELECT id, Unique_Email__c FROM Contact WHERE Email IN :leadEmails ];

    	Set<String> contactEmails = new Set<String>();
        Set<String> contactID = new Set<String>();
        for(Contact contact:contacts)
        {
            contactEmails.add(contact.Unique_Email__c);
            contactEmails.add(contact.id);
        }
    
        for(Lead lead:Trigger.new)
        {
            if(contactEmails.contains(lead.Email)){

// This is where i am having the problem Once i have the set
                lead.Contact__c = contactID.id;
            }
    	}
        
	}
	
	else
	{
        //gonna do something else here
	}
}

 So the issue is once I have the set I cant seem to get it to assing the contact to the Lookup field in the Lead object I get an error saying the initial term of the field expression must be an Sobject Set <String>

 

Not sure i udnerstand what i am doing wrong any help would be appreciated

I have a trigger I want to update a related field in the Lead Object To Store the Related Contact based on an email match. 

 

trigger LeadTrigger on Lead (before insert, before update, after insert, after update) 
{	
	if(Trigger.isBefore)
	{
        List<String> leadEmails = new List<String>();
    	for(Lead lead:Trigger.new)
    	{
        leadEmails.add(lead.Email);
    	}

    	List<Contact> contacts = [SELECT id, Unique_Email__c FROM Contact WHERE Email IN :leadEmails ];

    	Set<String> contactEmails = new Set<String>();
        Set<String> contactID = new Set<String>();
        for(Contact contact:contacts)
        {
            contactEmails.add(contact.Unique_Email__c);
            contactEmails.add(contact.id);
        }
    
        for(Lead lead:Trigger.new)
        {
            if(contactEmails.contains(lead.Email)){

// This is where i am having the problem Once i have the set
                lead.Contact__c = contactID.id;
            }
    	}
        
	}
	
	else
	{
        //gonna do something else here
	}
}

 So the issue is once I have the set I cant seem to get it to assing the contact to the Lookup field in the Lead object I get an error saying the initial term of the field expression must be an Sobject Set <String>

 

Not sure i udnerstand what i am doing wrong any help would be appreciated