0

I keep getting the following error on either field CaseEmailAddress or Action Take on G2 and I have no idea why? My previous trigger was working I just added a couple new fields like first name, last name, web form phone. Code coverage is at 100%.

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GrabCaseDescriptionText: data changed by trigger for field Action Take on G2:: data value too large: (value has been hidden): []

OR

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GrabCaseDescriptionText: data changed by trigger for field CaseEmailAddress: data value too large: (value has been hidden): []

This trigger will be looking at two different web submissions and getting sent to a case where I can create a lead from. I have 1 form from G2 (where its just using name) and another where the form submission is via first + last name.

I even updated my char limits for my text fields but that doesnt seem to be working.

Any help would be greatly apprecviated!

Trigger:

trigger GrabCaseDescriptionText on Case (before insert, before update) { for (Case c: Trigger.new) { if (c.Description != null) { List lines = new List(); lines = c.Description.split('\n');

     for (String line: lines) {
        if(line.contains('Email: ')){
            line.remove('Email: ');
            system.debug(line);
            c.CaseEmailAddress2__c = line.remove('Email: ');
        }
         if(line.contains('email: ')){
            line.remove('email: ');
            system.debug(line);
            c.CaseEmailAddress__c = line.remove('email: ');
        }
         if(line.contains('First name: ')){
            line.remove('First name: ');
            system.debug(line);
            c.First_Name__c = line.remove('First name: ');
        }
         if(line.contains('Last name: ')){
            line.remove('Last name: ');
            system.debug(line);
            c.Last_Name__c = line.remove('Last name: ');
        }
         if(line.contains('name: ')){
            line.remove('name: ');
            system.debug(line);
            c.Submitter_Name__c = line.remove('name: ');
        }
            if(line.contains('action takeN on G2: ')){
                line.remove('action takeN on G2: ');
                system.debug(line);
                c.Action_Take_on_G2__c = line.remove('action takeN on G2: ');
            }
            if(line.contains('industry: ')){
                line.remove('industry: ');
                system.debug(line);
                c.Industry__c = line.remove('industry: ');
            }
         if(line.contains('How many users are you looking to onboard?: ')){
                line.remove('How many users are you looking to onboard?: ');
                system.debug(line);
                c.Users_to_Onboard__c  = line.remove('How many users are you looking to onboard?: ');
         }
           if(line.contains('What service are you using today?: ')){
                line.remove('What service are you using today?: ');
                system.debug(line);
                c.Current_Device__c  = line.remove('What service are you using today?: ');
            }  
         if(line.contains('company size: ')){
                line.remove('company size: ');
                system.debug(line);
                c.Company_Size__c  = line.remove('company size: ');
            }
            if(line.contains('company: ')){
                line.remove('company: ');
                system.debug(line);
                c.Submitter_s_Company__c  = line.remove('company: ');
            }
            if(line.contains('phone number: ')){
                line.remove('phone number: ');
                system.debug(line);
                c.Submitter_s_Phone__c  = line.remove('phone number: ');
            }
         if(line.contains('Current phone number: ')){
                line.remove('Current phone number: ');
                system.debug(line);
                c.Web_Form_Phone__c  = line.remove('Current phone number: ');
            }  
            
        }
        if(c.CaseEmailAddress__c !=null){
            List<Contact> cons = [SELECT Id FROM Contact WHERE Email=:c.CaseEmailAddress__c LIMIT 1];
            if(cons.size()>0)c.ContactId=cons[0].id;
        }
    }
}   

}

Test Class

@isTest(SeeAllData=false)
public class TestCaseComment {
    static testMethod void insertCase() {
        Case c = new Case();
        c.Status = 'New';
        c.Origin = 'Email';
        c.Description = 
        'email: [email protected]'+
        'Email: [email protected]' +
        'name: Christopher Martin'+ 
        'First name: Christopher' + 
        'Last name: Martin' + 
        'How many users are you looking to onboard?: 2 - 5'+ 
        'What service are you using today?: Personal device' +
        'phone number: 09090909'+
        'Current phone number: 09090909' +
        'company: Wake Wash'+
        'action takeN on G2: Requested'+
        'company size: 2-10 employees'+
        'industry: Consumer Services'+
        'lead submitted at: 2022-07-28T09:39:15.059-05:00';
        insert c;
    

} }

1 Answer 1

1

You need to put actual line breaks inside the strings:

c.Description = 
    'email: [email protected]\n'+
    'Email: [email protected]\n'+
    'name: Christopher Martin\n'+ 
    'First name: Christopher\n'+ 
    'Last name: Martin\n'+ 
    'How many users are you looking to onboard?: 2 - 5\n'+ 
    'What service are you using today?: Personal device\n'+
    'phone number: 09090909\n'+
    'Current phone number: 09090909\n'+
    'company: Wake Wash\n'+
    'action takeN on G2: Requested\n'+
    'company size: 2-10 employees\n'+
    'industry: Consumer Services\n'+
    'lead submitted at: 2022-07-28T09:39:15.059-05:00';

You may want to write your code to handle the situation where data is too large.

As a side note, note that the various lines, such as:

line.remove('company size: ');

Are pointless, as they do not modify the original string.

You might also want to use startsWith or maybe even startsWithIgnoreCase, since it seems possible that you'll miss data if the field labels change at all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .