• Sheila Rashad
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hello everone, I need help on the following error message:
Reason: Apex trigger LeadConvert caused an unexpected exception, contact your administrator: LeadConvert: execution of AfterInsert

caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Your lead is missing a field mapping for the Pet Primary Caregiver,Household Allergies,Household Pets,Top Dogg K9 Exposure fields. 

LeadConvert Trigger:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
trigger LeadConvert on Lead (after insert) {

    ID acctID, ContID;
    /* Get the Id and MasterLabel from LeadStatus object */
    LeadStatus convertStatus = [ select Id, 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.WebForm__c == 'Free Trial') { */
        

        try {
        Account acct = new Account(Name=lead.LastName + ' Household', recordtypeid = '0123i000000paRjAAI');
        insert acct;
        // Once the account is inserted, the sObject will be populated with an ID. Get this ID.
        acctID = acct.ID;
      Contact cont = new Contact( Contact_type__c='Applicant', AccountId=acctID);
        insert cont;
            contID = cont.ID;
      
    } catch(DmlException e) {
        System.debug('An unexpected error has occurred: ' + e.getMessage());
    }
        
        

        if (!lead.isConverted) {
      Database.LeadConvert lc = new Database.LeadConvert();
      lc.setLeadId(lead.Id);
            
            //String oppName = lead.Name;
      //lc.setOpportunityName(oppName);
      lc.setAccountId(acctID);
      lc.setConvertedStatus(convertStatus.MasterLabel);
            Database.LeadConvertResult lcr = Database.convertLead(lc);
      System.assert(lcr.isSuccess());
            
      //leadConverts.add(lc);
    }
  }

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

Not sure if I should make these fields not required on the Salesforce side to prevent error or deactivate the trigger. Also discovered that a blank application can be submitted which should not be the case. Please advise how to remove the error message and if it should be addressed on the application side on the website or the Salesforce side. 
Hello everone, I need help on the following error message:
Reason: Apex trigger LeadConvert caused an unexpected exception, contact your administrator: LeadConvert: execution of AfterInsert

caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Your lead is missing a field mapping for the Pet Primary Caregiver,Household Allergies,Household Pets,Top Dogg K9 Exposure fields. 

LeadConvert Trigger:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
trigger LeadConvert on Lead (after insert) {

    ID acctID, ContID;
    /* Get the Id and MasterLabel from LeadStatus object */
    LeadStatus convertStatus = [ select Id, 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.WebForm__c == 'Free Trial') { */
        

        try {
        Account acct = new Account(Name=lead.LastName + ' Household', recordtypeid = '0123i000000paRjAAI');
        insert acct;
        // Once the account is inserted, the sObject will be populated with an ID. Get this ID.
        acctID = acct.ID;
      Contact cont = new Contact( Contact_type__c='Applicant', AccountId=acctID);
        insert cont;
            contID = cont.ID;
      
    } catch(DmlException e) {
        System.debug('An unexpected error has occurred: ' + e.getMessage());
    }
        
        

        if (!lead.isConverted) {
      Database.LeadConvert lc = new Database.LeadConvert();
      lc.setLeadId(lead.Id);
            
            //String oppName = lead.Name;
      //lc.setOpportunityName(oppName);
      lc.setAccountId(acctID);
      lc.setConvertedStatus(convertStatus.MasterLabel);
            Database.LeadConvertResult lcr = Database.convertLead(lc);
      System.assert(lcr.isSuccess());
            
      //leadConverts.add(lc);
    }
  }

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

Not sure if I should make these fields not required on the Salesforce side to prevent error or deactivate the trigger. Also discovered that a blank application can be submitted which should not be the case. Please advise how to remove the error message and if it should be addressed on the application side on the website or the Salesforce side.