You need to sign in to do that
Don't have an account?
Apex String Comparisons
I am attempting to compare two strings of text. I am trying to compare the subject of an email template and the subject of a task. A week ago the subject of the email template was shorter than 70 characters, now it has been changed and is longer. Here's the code.
trigger trgOnEOAMEmail on Task (before insert) { String ECOMMsubject = [select subject from emailtemplate where id = '00XR0000000DmjC' LIMIT 1].subject; System.debug('ECOMMsubject : ' + ECOMMsubject ); String EOAMsubject = [select subject from emailtemplate where id = '00XR0000000DmjM' LIMIT 1].subject; System.debug('EOAMsubject : ' + EOAMsubject ); String subEOAMsubject = 'Email: '+EOAMsubject.substring(0,70)+'...'; String subECOMMsubject = 'Email: '+ECOMMsubject.substring(0,70)+'...'; System.debug('subECOMMsubject: '+ subECOMMsubject ); System.debug('subEOAMsubject: '+ subEOAMsubject); FOR (Task act:System.Trigger.new) { System.debug('ACT ID:' + act.Id); System.debug('ACT AT:' + act.Activities_Type__c); System.debug('ACT Type:' + act.Type__c); System.debug('ACT Cat:' + act.Category__c); System.debug('ACT ON:' + act.Original_Need__c); System.debug('ACT Subject:' + act.Subject); System.debug('subECOMMsubject:'+subECOMMsubject); System.debug('subEOAMsubject :'+subEOAMsubject ); if(act.Subject.equals('Email: '+subECOMMsubject+'...') || (act.Subject.equals('Email: '+subEOAMsubject +'...'))) { act.Original_Need__c = 'Account Management'; act.Activities_Type__c = 'Email'; act.Type__c = 'Email'; act.Category__c = 'eComm'; } } }
I've checked the debug logs and act.subject does indeed equal the value of subECOMMsubject or subEOAMsubject. I can't figure out why this statement doesn't evaluate to true allowing the rest of this trigger to be kicked off.
It looks like your problem is here:
if(act.Subject.equals('Email: '+subECOMMsubject+'...') || (act.Subject.equals('Email: '+subEOAMsubject +'...'))) {
with
Try doing this and see if that resolves your issue:
All Answers
Here is the log to my apex trigger as well. It shows that the act.Subject does indeed equal either subEOAMsubject or subECOMMsubject.
It looks like your problem is here:
if(act.Subject.equals('Email: '+subECOMMsubject+'...') || (act.Subject.equals('Email: '+subEOAMsubject +'...'))) {
with
Try doing this and see if that resolves your issue: