function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MNaethlerMNaethler 

Trigger action before Converting

Hey guys,

 

i need to know how i can write a trigger that he will fire before i convert a lead into a company, that the trigger can check if the company is already there and perform a merge then? any ideas? 

 

 

Tim BarsottiTim Barsotti

You need to enable "validation and triggers from lead convert". To enable this from Setup, click Customize | Leads | Settings. Select "Enable Validation and Triggers from Lead Convert". 

 

If this option is not available you will need to file a Premier Support ticket to have SFDC enable it on the backend. 

 

http://login.salesforce.com/help/doc/en/customize_leadsettings.htm

 

http://login.salesforce.com/help/doc/en/leads_convert.htm

MNaethlerMNaethler

I already have this setting enabled, thanks anyway.

I meant how i can say the trigger that i want him to start before convertin,

like in another trigger from me :

 

trigger preventDuplicatedLeadEntries on Lead (before insert, before update) 

 

i tried smthn like (before convert) but it aint exists, if u know what i mean 

what have i do, i tried to take (before convert) but it aint exist if u know what i mean?

 

 

Tim BarsottiTim Barsotti

Something like this will suite your needs: 

trigger test on Lead (before update) {
 for(Lead lead:Trigger.new) {
  if (Lead.IsConverted)
  //do something here with converted leads
 }
}

 

MNaethlerMNaethler

hey again,

 

and well, it aint works.

 

trigger checkDoubleEntriesBeforeGetConverted on Lead (before update)
{
    Map<String, Lead> leadConvertToOppertunity = new Map<String, Lead>();
    for (Lead lead : System.Trigger.new)
    {
        if (!lead.isConverted)
    	{
            if (((lead.Company != null) && (System.Trigger.isInsert || (lead.Company != System.Trigger.oldMap.get(lead.Id).Company)))
                &&
                ((lead.Street != null) && (System.Trigger.isInsert || (lead.Street != System.Trigger.oldMap.get(lead.Id).Street)))
                 &&
               	  ((lead.Phone != null) && (System.Trigger.isInsert || (lead.Phone != System.Trigger.oldMap.get(lead.Id).Phone))
                  ||
                   ((lead.MobilePhone != null) && (System.Trigger.isInsert || (lead.MobilePhone != System.Trigger.oldMap.get(lead.Id).MobilePhone)))))
            {
                if (leadConvertToOppertunity.containsKey(lead.Company))
                {
                    lead.Email.addError('Another lead has the same company.');   
                }
                else
                {
                    leadConvertToOppertunity.put(lead.Company, lead);
                }
            }

 

i did it exactly but the trigger seems not to start,

for better explanaiton, before i click on convert, i want that if the trigger checks that we got double entries, that he opens automatically a popup where i can merge all fields manually.

i dont have the popup atm, but he should still send an error message as u can see

Tim BarsottiTim Barsotti

System.Trigger.isInsert will always evaluate to false for a (Before Update) trigger. I am not sure why your trigger is set to compare phone, street, etc.

 

Are you wanting to check to ensure there are not multiple companies being converted at once? Or are you wanting to check existing companys?

 

If you want a popup, to intercept prior to committing you will need a visual force page with a custom controller instead of a trigger.

MNaethlerMNaethler

hey Tim,

 

i want to check if a company exists when i tried to convert a new lead

 

couldn't i call the the visual force page from the trigger to "pop up" ?

Tim BarsottiTim Barsotti

No. A popup would be on the front end and you are wanting to manipulate it from the database level. Those most you could do is to throw an error before the DML completes. 

 

You would need a custom VF page and controller to manipulate the UI it in this way.

MNaethlerMNaethler

oh damned, ok thank you :)

 

still got this prob with the check if other companies or accounts with same adress maybe or email, but i think we take an existing app,

 

so thanks anyway