+ Start a Discussion

Is there any way to take the user to a specific lead/account through Apex code?

Here is what I am trying to do:


I want to allow the user to insert a new lead, catch the insert with a trigger, go into an apex class, block the insert based on some criteria we have internally and then take them to a related lead.


Thanks for any help you can provide.


No, you can not do this today.  You can override the new lead button/action with a Visualforce page and upon save a trigger can express the error and the controller can handle it accodingly.


The Dupeblocker product from CRMfusion has this capability.  It is a commercial program, however.  Check it out on the AppExchange


Has what functionality, redirecting a user to a specific url from a trigger (and not using Visualforce)?  I'd be interested in understanding how they accomplish this.




According to their website:


When designing scenarios the administrators decide what to do when a duplicate is discovered. Different actions such as "Block Insert with Error Message", "Redirect to Proper Record" or "Allow Duplicate but Display Warning" are selectable based upon whether the duplicate was discovered during an insert (new record) or an update (modify existing record).


From our implementation, it blocks the creation of the duplicate with a error message that looks like a validation, and includes a link to the proper record.


Thanks Jim.  Fundamentally there is no supported way to actually perform the redirect in our product which is what i was looking for. There are some interesting statements in that product description though.  


Which "option" are you using? Is it the "Block with error" or "Redirect option"


Thanks again for sharing.


We have several of the options implemented, depending on specific criteria. 

Some cases, we allow the duplicate to get added, then my team gets and email and report to review, others we just block with an error, and some we use the Redirect.


It actually looks like they use some type of scontrol, combined with the error. They redirect to the original duplicate, and display a modal dialog telling the user what do do.  In the case of multiple duplicates, they display a modal list in the corner of the page as well.

So, excluding the dialog boxes, it does appear they do some type of automated redirection, I guess you would have to ask CRMfusion if you wanted to know their secret.




Thanks again.




Correct, they use an S-Control. They were grandfathered in because they had done this before s-Controls were replaced. The question becomes, how does one do this with no s-control for those of us developers not allowed to us s-controls.


We're working on a feature to do this in a supported way as there has never been one.


For the record, I'd love an sObject.addMessage method that took an argument of severity (INFO, WARN, etc.) that the user had to acknowledge before DML was committed. If we had a boolean "ignoreWarnings" flag on the Database.insert & friends methods I think this could be a reasonably elegant solution to a common problem.




Apex manual says:


"Additionally, if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime


If I have a duplicate lead, essentially, I cannot delete in it's after insert trigger (I could write an async. process to do it).


However, I am able to write a  "merge ExistingLead, LeadBeingInserted" statement.

When I do this, from the UI, as soon as someone tries to save the record, instead of detail page, you get the "record has been deleted" message.

Is this supported behavior?