You need to sign in to do that
Don't have an account?
[Lindsey Kiken]
Receiving Apex Trigger Compile Error: unexpected token: '<'
I have a trigger that successully fires upon the system receiving an inbound email related to a Case record. This trigger's purpose is to stamp the inbound email's body into a text field on the Case object. The working code is as follows:
I received the error "Error: Compile Error: unexpected token: '<' at line 34 column 67". I have tried to play around with different ways of adding in <BR/>'s into this field, but continue to run into this same error code. Please see below for the updated work in progress code:
trigger CopyEmailReplyBody on EmailMessage (after insert) { Set<ID> caseSet = new Set<ID>(); Map<Id, String> emailBodyMap = new Map<Id, String>{}; for (EmailMessage so : Trigger.new) { if(so.ParentId.getSObjectType() == Case.sObjectType && so.Incoming){ caseSet.add(so.parentid); emailBodyMap.put(so.ParentId, so.TextBody); } } Map<Id,case> caseMAP = new Map<Id,case>([SELECT Latest_Email_Reply__c FROM Case WHERE id in:caseSet]); for(Case c:caseMAP.values()){ c.Latest_Email_Reply__c = emailBodyMap.get(c.Id); update c; } }My users just asked for a new requirement in that the values stamped into the text field "[FromAddres] + BR() + [FromName] + BR() + [Subject] + BR() + BR() + [Body]". Sounded simple enough, but I ran into a silly issue:
I received the error "Error: Compile Error: unexpected token: '<' at line 34 column 67". I have tried to play around with different ways of adding in <BR/>'s into this field, but continue to run into this same error code. Please see below for the updated work in progress code:
trigger CopyEmailReplyBody on EmailMessage (after insert) { Set<ID> caseSet = new Set<ID>(); Map<Id, String> emailBodyMap = new Map<Id, String>{}; for (EmailMessage so : Trigger.new) { if(so.ParentId.getSObjectType() == Case.sObjectType && so.Incoming){ caseSet.add(so.parentid); emailBodyMap.put(so.ParentId, so.TextBody); } } Map<Id, String> emailSubjectMap = new Map<Id, String>{}; for (EmailMessage so : Trigger.new) { if(so.ParentId.getSObjectType() == Case.sObjectType && so.Incoming){ caseSet.add(so.parentid); emailSubjectMap.put(so.ParentId, so.Subject); } } Map<Id, String> emailFromAddressMap = new Map<Id, String>{}; for (EmailMessage so : Trigger.new) { if(so.ParentId.getSObjectType() == Case.sObjectType && so.Incoming){ caseSet.add(so.parentid); emailFromAddressMap.put(so.ParentId, so.FromAddress); } } Map<Id, String> emailFromNameMap = new Map<Id, String>{}; for (EmailMessage so : Trigger.new) { if(so.ParentId.getSObjectType() == Case.sObjectType && so.Incoming){ caseSet.add(so.parentid); emailFromNameMap.put(so.ParentId, so.FromName); } } Map<Id,case> caseMAP = new Map<Id,case>([SELECT Latest_Email_Reply__c FROM Case WHERE id in:caseSet]); for(Case c:caseMAP.values()){ c.Latest_Email_Reply__c = emailFromNameMap.get(c.Id) + <br /> + emailFromAddressMap.get(c.Id) + <br /> + <br /> + emailSubjectMap.get(c.Id) + <br /> + <br /> + emailBodyMap.get(c.Id); update c; } }Thoughts?
Is Latest_Email_Reply__c a text field? If so, this is not possible.
If this is a text area you can simply use '\n'; http://salesforce.stackexchange.com/questions/74215/save-newline-in-text-field
Thanks
All Answers
You can try this.
Please do let me know if it helps you.
Regards,
Mahesh
I tried that route earlier, but it unfortunately then applies the <br> as the literal text vs the function. Any other thoughts?
Cheers,
Lindsey
Please make sure that Latest_Email_Reply__c is a text area / rich text area.
Regards,
Mahesh
Is Latest_Email_Reply__c a text field? If so, this is not possible.
If this is a text area you can simply use '\n'; http://salesforce.stackexchange.com/questions/74215/save-newline-in-text-field
Thanks
Thank you again for all of your help!