I do not have lot of knowledge on the subject of merging, but seeing as no one has answered yet, I want to throw in my two cents.
Check your capitalization of newLeads
on your 3rd line! You reference it as newleads
not newLeads
. If this is actually like this in your code, it will cause problems. If this is not the case, continue reading...
On the Merge Statement Documentation Page it states that you can either pass one or two sObjects to the merge statement as the second parameter. If you are passing two objects, you should do so in a list (as you are doing - which is good).
merge sObject sObject;
merge sObject sObject[];
What might be catching you here is that you can only merge one or two records into one record. Since I can't see what your list look like, all I can do is suggest that you ensure that at most two records are being populated into your newLeads
list.
A couple of questions that you should investigate:
- Is
newLeads
always one or two records?- Do you have a few similar leads in
emailSet
that you may be incorrectly recognizing as the same lead?- Are you ensuring that your assert statement is querying fresh results for the modified lead?