DupeBlocker Errors When Creating a Duplicate Record via a Custom Visualforce Page
 

QUESTION:

I have created a custom Visualforce page for inserting my records, but when a duplicate is detected by DupeBlocker I am getting the following error message.  How can I get the HTML to render correctly?

Sample Error Text:

This example was for a duplicate Lead that triggered a block from "Do Not Insert", but it will occur with any object (Account,Contact or Lead) that triggers a block:

<div style="padding:0.7em;font-size:11px;width:40em;margin:0 auto;background-color:#FBF9EE;border-color:#FCEFA1;border-width:1px;border-style:solid;border-radius:4px;"> <P align="center"><font color="black"><strong>DupeBlocker Duplicate Prevention</strong></font></P> <P align="left"><font color="red">Potential duplicate Lead found with a similar name and the same e-mail address.</font><font color="black"><ul> <li align="left"><a name="db_BlockLink" href="/00QE000000OkGL9MAN">John Doe</a></li> </ul></font></P></div><BR/> <script type="text/javascript"> var __sfdcSessionId = "00DE0000000dScm!AQUAQJAFj.RQf4n5JUmVxbiaeUZBTHSYb4LadBAFqkeDCTkFoJA_uiCW5mZPbsaSKPpZk1FNHzD8.q02nEV7AGTW5GxXB9uC"; </script><script src="/soap/ajax/29.0/connection.js" type="text/javascript"></script><script src="/soap/ajax/29.0/apex.js" type="text/javascript"></script><script type="text/javascript"> sforce.apex.execute("CRMfusionDBR101/DB_WebServices","IncrementScenarioBlockCount",{scenarioId:"a0LE0000007tmPAMAY", blockCount:1}, {onSuccess: doNothing, onFailure: onError} ); function doNothing(){} function onError(error){if(error.faultcode.toLowerCase()=="sf:insufficient_access"){alert("You do not have access to the DupeBlocker web services. Please contact your Salesforce administrator.\r\nThe configuration instructions are in the DupeBlocker install guide."); } else{alert(error.toString());} } var blockLinks = document.getElementsByName("db_BlockLink"); if ( ( location.href.toLowerCase().indexOf( "?isdtp=" ) >= 0 || location.href.toLowerCase().indexOf( "&isdtp=" ) >= 0 ) && blockLinks != null && blockLinks.length > 0 ) { for ( var linkLoop = 0; linkLoop < blockLinks.length; linkLoop ++ ) blockLinks[linkLoop].href += "?isdtp=vw"; } </script> 

If the scenario was set to "Redirect to Existing" the message will look like this:

DupeBlocker: Duplicate found, insert blocked. Redirecting to the existing record. <script type="text/javascript"> var __sfdcSessionId = "00DE0000000dScm!AQUAQBtF2Y.NVju5kOVjfElK7TcBCQCd.IIno41_fGA7FdwpzVZh_ZeTxu_h2B6HwSBSo3XgtpSOnjMEVoF9Q2tA1qCJxoxu"; </script><script src="/soap/ajax/29.0/connection.js" type="text/javascript"></script><script src="/soap/ajax/29.0/apex.js" type="text/javascript"></script><script type="text/javascript"> sforce.apex.execute("CRMfusionDBR101/DB_WebServices","IncrementScenarioBlockCount",{scenarioId:"a0LE0000007tmPAMAY", blockCount:1}, {onSuccess: doNothing, onFailure: onError} ); function doNothing(){} function onError(error){if(error.faultcode.toLowerCase()=="sf:insufficient_access"){alert("You do not have access to the DupeBlocker web services. Please contact your Salesforce administrator.\r\nThe configuration instructions are in the DupeBlocker install guide."); } else{alert(error.toString());} } location.href="/apex/CRMfusionDBR101__DB_Match_Redirector?dupes=%2F00QE000000OkGL9MAN%08John%26nbsp%3BDoe"; </script>  

ANSWER:

This error is being generated because a record was created/updated which triggered a "block" or "redirect" message within DupeBlocker and the custom Visualforce page is not handling the HTML correctly for displaying the error that is being returned.

To resolve this, first update the Visualforce page to include an <apex:pageMessages escape="false" /> tag in place of the current tag being used (probably <apex:messages />) to properly output the DupeBlocker error. This emulates how SalesForce.com displays errors on almost all screens.

Second, the controller method that inserts/updates the record must wrap the insert/update in a try/catch block and any exceptions have to be added to the page messages, similar to this example:

    public pageReference saveLead()

    {

        try

        {

            insert newLead;

        } catch (Exception e) {

            ApexPages.addMessages(e);

            return null;

        }

        return new pageReference( '/' + newLead.id );

    }

To determine which Apex class is the controller, look for the controller or extensions parameter of the <apex:page> tag.   To find out which method in that controller is being called, look for the <apex:commandButton> tag for the Save button and see what the action is.  The action should be something like "{!saving}" where saving is the name of the method being called.  Within that method look for the insert statement and then wrap it in a try/catch block as described above.  Similar changes should be made for any Visualforce edit pages, though you'll be looking for updates in the save methods instead of inserts.



Related Attachments
 None Found





Does this Solution help you answer your question?