lundi 1 septembre 2014

"CONTACT" record should be CONVERT back to the "LEAD" record when ACCOUNT NAME in contact is deleted


Vote count:

0




*Whenever the Account on Contact record changes, the contact should be converted back to a Lead. i have mapping fields from contact to lead. Is this possible ? how to achieve this ?


manually done by writing a Trigger


here is my trigger*



enter code here
<pre><code>
trigger insertLead on Contact (before update,before delete) {
Set<Id> aId = new Set<Id>();
Lead myLead = new Lead();
for (Contact opp : Trigger.new ) {
aId.add(opp.AccountId);
List<Account> acc = [select Name from Account where Id in:aId];
List<Contact> con = [select LastName,FirstName from Contact where accountId = :aId];
for(Account a: acc){
myLead.Company = a.Name;
}
for(Contact c: con)
{
myLead.LastName = c.LastName;
myLead.FirstName = c.FirstName;
}
insert myLead;
}
</code></pre>


*Error:Apex trigger insertLead caused an unexpected exception, contact your administrator: insertLead: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company]: [Company]: Trigger.insertLead: line 15, column 1 *



asked 59 secs ago







"CONTACT" record should be CONVERT back to the "LEAD" record when ACCOUNT NAME in contact is deleted

Aucun commentaire:

Enregistrer un commentaire