function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ron929Ron929 

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.

 

Best Answer chosen by Admin (Salesforce Developers) 
XactiumBenXactiumBen

It looks like your problem is here:

 

 

if(act.Subject.equals('Email: '+subECOMMsubject+'...') || (act.Subject.equals('Email: '+subEOAMsubject +'...'))) {

 

 You've already added 'Email: ' and '...' to the start and end of these variables so adding them again means you are comparing:
Email: American Century Investments: Thank You for Your Interest in Exclusive...

 

with

 

Email: Email: American Century Investments: Thank You for Your Interest in Exclusive......

 

Try doing this and see if that resolves your issue:

if(act.Subject.equals(subECOMMsubject) || 
act.Subject.equals(subEOAMsubject)) {

 

 

 

All Answers

Ron929Ron929

Here is the log to my apex trigger as well.  It shows that the act.Subject does indeed equal either subEOAMsubject or subECOMMsubject.

 

 

*** Beginning trgOnEOAMEmail on Task trigger event BeforeInsert for null

20090330132033.225:Trigger.trgOnEOAMEmail: line 2, column 31: SOQL query with 1 row finished in 30 ms
20090330132033.225:Trigger.trgOnEOAMEmail: line 3, column 9: ECOMMsubject : American Century Investments: Thank You for Your Interest in eCommunication
20090330132033.225:Trigger.trgOnEOAMEmail: line 4, column 30: SOQL query with 1 row finished in 11 ms
20090330132033.225:Trigger.trgOnEOAMEmail: line 5, column 9: EOAMsubject : American Century Investments: Thank You for Your Interest in Exclusive Online Account Management
20090330132033.225:Trigger.trgOnEOAMEmail: line 8, column 9: subECOMMsubject: Email: American Century Investments: Thank You for Your Interest in eCommunic...
20090330132033.225:Trigger.trgOnEOAMEmail: line 9, column 9: subEOAMsubject: Email: American Century Investments: Thank You for Your Interest in Exclusive...
20090330132033.225:Trigger.trgOnEOAMEmail: line 11, column 4: SelectLoop:LIST:SOBJECT:Task
20090330132033.225:Trigger.trgOnEOAMEmail: line 12, column 9: ACT ID:null
20090330132033.225:Trigger.trgOnEOAMEmail: line 13, column 9: ACT AT:Inbound
20090330132033.225:Trigger.trgOnEOAMEmail: line 14, column 9: ACT Type:null
20090330132033.225:Trigger.trgOnEOAMEmail: line 15, column 9: ACT Cat:null
20090330132033.225:Trigger.trgOnEOAMEmail: line 16, column 9: ACT ON:null
20090330132033.225:Trigger.trgOnEOAMEmail: line 17, column 9: ACT Subject:Email: American Century Investments: Thank You for Your Interest in Exclusive...
20090330132033.225:Trigger.trgOnEOAMEmail: line 18, column 9: subECOMMsubject:Email: American Century Investments: Thank You for Your Interest in eCommunic...
20090330132033.225:Trigger.trgOnEOAMEmail: line 19, column 9: subEOAMsubject :Email: American Century Investments: Thank You for Your Interest in Exclusive...

Cumulative resource usage:

Resource usage for namespace: (default)
Number of SOQL queries: 2 out of 20
Number of query rows: 2 out of 1000
Number of SOSL queries: 0 out of 0
Number of DML statements: 0 out of 20
Number of DML rows: 0 out of 100
Number of script statements: 17 out of 10200
Maximum heap size: 0 out of 100000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 10
Number of record type describes: 0 out of 10
Number of child relationships describes: 0 out of 10
Number of picklist describes: 0 out of 10
Number of future calls: 0 out of 10
Number of find similar calls: 0 out of 0
Number of System.runAs() invocations: 0 out of 0

Total email recipients queued to be sent : 0
Static variables and sizes:
trgOnEOAMEmail:ECOMMsubject:75
trgOnEOAMEmail:EOAMsubject:96
trgOnEOAMEmail:subECOMMsubject:80
trgOnEOAMEmail:subEOAMsubject:80
XactiumBenXactiumBen

It looks like your problem is here:

 

 

if(act.Subject.equals('Email: '+subECOMMsubject+'...') || (act.Subject.equals('Email: '+subEOAMsubject +'...'))) {

 

 You've already added 'Email: ' and '...' to the start and end of these variables so adding them again means you are comparing:
Email: American Century Investments: Thank You for Your Interest in Exclusive...

 

with

 

Email: Email: American Century Investments: Thank You for Your Interest in Exclusive......

 

Try doing this and see if that resolves your issue:

if(act.Subject.equals(subECOMMsubject) || 
act.Subject.equals(subEOAMsubject)) {

 

 

 

This was selected as the best answer