• Tess Sta Romana
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Auto lead converter works in sandbox but it fails when deployed in production.

ERROR MESSAGE:
---------------------------
Class Name     Method Name     Error Message
unsubscribetestUnsubscribeSystem.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, You're creating a duplicate record. We recommend you use an existing record instead. 
Stack Trace: Class.unsubscribe.testUnsubscribe: line 110, column 1

unsubscribetestUnsubscribe2System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, You're creating a duplicate record. We recommend you use an existing record instead. 
Stack Trace: Class.unsubscribe.testUnsubscribe2: line 141, column 1

CODE:
---------
trigger AutoConverter on Lead (after update) {
LeadStatus convertStatus = [
          select MasterLabel
          from LeadStatus
          where IsConverted = true
          limit 1
     ];
     List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

     for (Lead lead: Trigger.new) {
          if (!lead.isConverted && lead.status == 'Sales Qualified') {
               Database.LeadConvert lc = new Database.LeadConvert();
               String oppName = lead.Name;
               
               lc.setLeadId(lead.Id);
               lc.setOpportunityName(oppName);
               lc.setConvertedStatus(convertStatus.MasterLabel);
               
               leadConverts.add(lc);
          }
     }

     if (!leadConverts.isEmpty()) {
          List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
     }
}
Hi,

everytime someone creates an Event for an Opportunity I want to update the Next Steps-Field with the Event-name+Date.
I guess I have to code a Trigger, but I never coded one. Help anyone?

Greets