3

I would like to know how to stop converting Lead to Account in before insert trigger without addError() method?

To be more precise I try to achieve the following: 1. Stop the process of converting Lead to Account. 2. Display message in the convert Lead to Account page that the respective Lead is not converted. 3. Set and Update the Lead.Status__c field to 'Existing Deal'.

I've tried the above in before insert trigger and I used addError() method to stop the process of converting Lead to Account as well as to dispaly message in the convert page that the Lead is not converted but the problem is that the addError() method is making a rollback of my changes and I can neither save nor update my changes and records into the Lead database table. I used @future method as well as a savepoint because I thought it will help me set and update my changes but it did not help. Therefore I decided to start investigating and searching for a feasible way to achive what I want via VF by using controller.

Could you please advise how to achieve what I want either by using trigger or controller?

Regards,

Dilyan

3

You cant achieve this via trigger for sure as you have figured it out .With add error you will see everything rolling back and at same time you want to update status of lead as well which is not possible .

Yes with your custom button you should be able to open a visualforce page and achieve desired output .But this means lot of visualforce and apex work .

Apex comes with database.leadconvert() system method which is going to be your friend for doing conversion if needed and for scenario where you need to show message and change status or update lead use apex:pagemessages with addmessage

Some reference link to get started

Lead convert Class

Add message class

Pseudo Code

if(condition){
  //Update lead
  apexpages.addmessage('lead is not converted');
}else{
 //Convert lead
}
  • Ok, so far so good, but because I am willing to strive and create a custom button which invetably will lead towards creating my own custom vf page what I would like to know and could you please advise how to be able to get and copy the source of my current vf lead convert page and change only the part where the convert button is involved. The only customization I need is to change the functionality of the convert button? Could you please help and advise because I strive to achieve that for such a long time? – Dylan D Nov 23 '15 at 14:29
  • 2
    You will have to write vf from scratch ....Here is some sample to get you going interactiveties.com/blog/2014/… ... An appexchange package appexchange.salesforce.com/… – Mohith Shrivastava Nov 23 '15 at 14:34
  • Ok, I've already went throught the link you suggested about the LeadConvert Class but I didn't see the part where and how I can stop the the process of converting Lead to Account. 1. Stop the process of converting Lead to Account. Could you please advise how this can be achieved either in trigger or in controller? – Dylan D Nov 23 '15 at 14:42
  • On what criteria you want to stop.You need just a if statement there ? – Mohith Shrivastava Nov 23 '15 at 14:51
  • Indeed, I use an if statement and check whether isConverted = false as well as I check whether the value/s set in some custom Lead fields coincide with value/s in some Account fields and if they coincide I stop the convert process. The check between the fields are working, I can guarantee that. But in the end what I want is merely to know is how to be able to stop converting Lead to Account either with or without the checks. Could you plsase advise how can I stop the process? – Dylan D Nov 23 '15 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.