You need to sign in to do that
Don't have an account?
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,
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:
Thanks John, that seems like cleaner way of doing things. I will look into that and post any issues I am having.