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
SunadminSunadmin 

Compile Error SObject:LIST:SOBJECT:Lead

Hello,

I am modifying a trigger I found in the developer community for checking duplicate leads. Here is the trigger that I downloaded and modified:

 

//This Trigger fires on the Lead object and checks for duplicate e-mail
// zip code and phone number fields
Trigger leadDupCheck on Lead(before insert, before update)

{
//Check to be sure zip and e-mail fields aren't empty
if (Trigger.new.Email !=null&& Trigger.new.PostalCode !=null&& Trigger.new.Phone !=null ){

//This is the query for duplicate e-mail and zip code fields

Lead[]dup = [select id from Lead WHERE Email = :Trigger.new.Email AND PostalCode = :Trigger.new.PostalCode AND Phone = :Trigger.new.Phone ];

// If there is a duplicate then an error message is displayed
// If there is no duplicate information, the program keeps going

    if ( dup.size() > 0 ) {Trigger.new.[Email].addError('This is a   duplicate Lead, do not re-enter');
	}
	else
	{
	 }
      }
}

 I compiled it and received the following error:

Compile Error: Initial term of field expression must be a concrete SObject:LIST:SOBJECT:Lead at line 9 column 49

Which is based on:

 

 

Lead[]dup = [select id from Lead WHERE Email = :Trigger.new.Email

 

 So then I tried to set up an sObject for the Lead:

 

Lead a = new Lead();
SObject s = [select id from Lead WHERE Email = :Trigger.new.Email AND PostalCode = :Trigger.new.PostalCode AND Phone = :Trigger.new.Phone ];

 

 

And received the following error:

Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Lead

 

I was reading some other posts and noticed that trigger.new is used for arrays and that I should use a loop through records. I was also wondering about the “Lead []dup” for the duplicate leads if I had that set up correctly.

Thanks,

jkucerajkucera

The error results as you have to specify which lead to check.

 

To get to the bigger problem, it may be easiest to create a custom field that is a formula of all 3 fields, and check for dupes across that custom field as the code is a bit cleaner.

 

See this post:

http://community.salesforce.com/t5/Apex-Code-Development/Prevent-duplicate-Lead-Trigger/m-p/151406

 

The basics of the trigger are something like this:

 

trigger leadDuplicatePreventer on Lead (before insert, before update) {
    Map<String, Lead> leadMap = new Map<String, Lead>();
    for (Lead lead : System.Trigger.new) {
        if ((lead.DupeCheck__c != null) &&
            (System.Trigger.isInsert || (lead.DupeCheck__c != System.Trigger.oldMap.get(lead.Id).DupeCheck__c))) {
            if (leadMap.containsKey(lead.DupeCheck__c)) {
                lead.DupeCheck__c.addError('Another new lead has the ' + 'same info.');
            } else { 
                leadMap.put(lead.DupeCheck__c, lead); 
            }//if 2
        }//if 1   
    }//for

    for (Lead lead : [SELECT DupeCheck__c FROM Lead WHERE DupeCheck__c IN :leadMap.KeySet()]) {
        Lead newLead = leadMap.get(lead.DupeCheck__c);
        newLead.DupeCheck__c.addError('A lead with this info already exists.');
    }
}

 

 

SunadminSunadmin

Thanks John, that seems like cleaner way of doing things. I will look into that and post any issues I am having.