You need to sign in to do that
Don't have an account?
phantom1982
Simple question
Hi Code Gurus,
Can someone plesae tell if we can use a List of standard objects with all its available methods like size() etc in a constructor?
this.email_c = parameters.get('PersonEmail'); this.dup = [SELECT id from Account WHERE PersonEmail =: email_c]; if(dup.size()>0){ this.duplicatelead = true; }
this code should set the duplicatelead to true everytime there's a duplicate record on the basis of email. But its not happening, the list size stays 0 always. Any idea why?
Yes, we can use all methods. But make sure your query is returning the result over which you are writing a loop. Use System.Debug() to check it.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Well query is returning 20 records but still the duplicate account is being created.
Let me put all the details here. It's web to lead generation code, Leads are coming in from web pages and a standard controller class has all the code for lead generation, its below:
Now I have tried various scenarios but duplicate account is being created. Only when i disable the dup.size() check and set the value of duplicatelead flag to true everytime, it works fine and doesnt create account. but if the check is enabled, it still creates. The list is returning more than 20 records so its fine as far as the size is concerned.
I would try a few things.
a) Print out the value of this.email_c (ie. System.debug('[' + this.email__c + ']') either to log or elsewhere). Note I suggest putting hte result in brackets. Perhaps you're getting whitespace that is causing the query to fail.
b) Similarly, dump the result of "SELECT id from Account WHERE PersonEmail =: this.email_c". In fact, I'd also move the colon, so it reads "SELECT id from Account WHERE PersonEmail = :this.email_c"
That way you'll understand exactly why it's failing etc.
Jon,
I have tried and everything is perfect with the code. The test gives the right results but when the lead is created from the web page, it generates duplicate. Below is the debug log and it has everything working fine i.e. returns to fail page when a duplicate record is found:
But when lead is generated with the Web page, it still creates a duplicate.