I have an email to case where a person sends a template containing specific values to a particular address that creates a case in salesforce. I want to pick up the values from the case description field and insert it into different custom fields.
Mapping:
Media Request Type: Choose an item.
MCM Account #: ##########
Original Account #: ##########
Consumer Name: First Name Last Name
Company: Company Name
Document Type: Choose an item.
Document Date: Click or tap to enter a date.
Apex Trigger:
trigger FieldUpdate on Case (before insert){
Map<String, String> fieldListMap = new Map<String, String>{
'Media Request Type: ' => 'Media_Request_Type__c',
'MCM Account #: ' => 'MCM_Account_Number__c',
'Original Account #: ' => 'Original_Account_Number_c',
'Consumer Name: ' => 'Customer_Name__c',
'Company: ' => 'Company_c',
'Document Type: ' =>'Media_Document_Type__c'
};
system.debug('fieldListMap-->'+fieldListMap);
List<String> descpSplitList;
List<String> labelValuePairSplitList;
for(Case cas : trigger.new){
if(!String.isBlank(cas.Description)){
descpSplitList = cas.Description.split('\n');
system.debug('descpSplitList -->'+descpSplitList );
for(String labelValuePair : descpSplitList){
labelValuePairSplitList = labelValuePair.split(':');
if (
labelValuePairSplitList.size() > 1 &&
fieldListMap.containsKey(labelValuePairSplitList[0])
) {
cas.put(fieldListMap.get(labelValuePairSplitList[0]), labelValuePairSplitList[1]);
}
}
}
}
}
This trigger isn't running when I send the email to case,can anyone provide knowledge on how to achieve this or how this trigger can be fixed?