+ Start a Discussion
saariko.ax241saariko.ax241 

InboundEmail - not working for an group

I have written an Apex class, that converts incoming emails according to the toAddress  (I know, it's great - thanks ^^ )

 

anyway, it is working perfect, when I send the email to the emailService generated address. However, in order that my users will not see such addresses, I create an alias group in our mail server (google for instance) and give the name a more suitable/readable name.

Here where the class breaks.

 

First debug code is with the direct address, as you can see, the SOQL returns 1 row (as should)

10:21:15.091 (91499000)|SOQL_EXECUTE_BEGIN|[33]|Aggregations:0|select Id from User where Alias = :tmpVar1
10:21:15.097 (97818000)|SOQL_EXECUTE_END|[33]|Rows:1

 

Second log, is when using th elias/group  (the only address in the group is the same one as in first example) however, this time, nothing is returned from the SOQL

10:14:46.127 (127098000)|SOQL_EXECUTE_BEGIN|[33]|Aggregations:0|select Id from User where Alias = :tmpVar1
10:14:46.132 (132488000)|SOQL_EXECUTE_END|[33]|Rows:0

 

I assume it's something in the way either Google transforms/creates/forwards email?

 

Anyone has an idea?

saariko.ax241saariko.ax241

ok, some more information.

 

I have executed with full debug. I think that the toAddresses[] is populated both with the original address (the group) and also with every single email that is in the list.

So I have to tweak my code to go over the <LIST> and to check for the beginning of the known string I use (lead).

 

I still get an error, here is some more of relevant code. 

 

This is my Apex code:

			Boolean isMissing = true;
			Integer i = 0;
	    	
			// if many toAddresses look for the one with : lead at the beginning
	    	while (isMissing && i-1 < email.toAddresses.size() ){
		    	sourceText = email.toAddresses[i].split('@');
		    	mParams = sourceText[0].split('\\.');
		    	
		    	if (mParams[0] == 'lead')
		    		isMissing = false;
		    	else
		    		i++;
	    	}

 

These are lines from the debug log:

  • some clarifications: test.processor@optite... is the group I created.
  • It contains a single email: lead.saarm.processr@.......apex.salesforce.com mail.

 

11:07:13.144 (144793000)|VARIABLE_ASSIGNMENT|[-1]|this.subject|"Re: test"|0x702f2bd6
11:07:13.144 (144808000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
11:07:13.144 (144813000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.144 (144831000)|VARIABLE_ASSIGNMENT|[-1]|this.plainTextBodyIsTruncated|false|0x702f2bd6
11:07:13.144 (144860000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:34
11:07:13.144 (144865000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.144 (144887000)|VARIABLE_ASSIGNMENT|[-1]|this.toAddresses|["test.processor@optit (6 more) ..."]|0x702f2bd6
11:07:13.144 (144907000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:292
11:07:13.144 (144912000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.144 (144936000)|VARIABLE_ASSIGNMENT|[-1]|this.references|["\u003CCAEYMRoxMYKDfEjM1Lf (48 more) ...","\u003CCAEYMRoxwwWamgU-oss (48 more) ...","\u003CCAEYMRowxqwP2iBeRp7 (48 more) ...","\u003CCAEYMRox1LY1ws9D370 (48 more) ..."]|0x702f2bd6
11:07:13.144 (144955000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:17
11:07:13.144 (144960000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.144 (144971000)|VARIABLE_ASSIGNMENT|[-1]|this.replyTo|"saar@mail.com"|0x702f2bd6
11:07:13.144 (144985000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:17
11:07:13.144 (144989000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.145 (145000000)|VARIABLE_ASSIGNMENT|[-1]|this.fromAddress|"saar@mail.com"|0x702f2bd6
11:07:13.145 (145017000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:15
11:07:13.145 (145025000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.145 (145044000)|VARIABLE_ASSIGNMENT|[-1]|this.fromName|"Saar "|0x702f2bd6
11:07:13.145 (145067000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1864
11:07:13.145 (145076000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.145 (145104000)|VARIABLE_ASSIGNMENT|[-1]|this.htmlBody|"\u003Cdiv dir=\"ltr\"\u003E\u003Cbr c (1844 more) ..."|0x702f2bd6
11:07:13.145 (145131000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.145 (145139000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.145 (145164000)|VARIABLE_ASSIGNMENT|[-1]|this.messageId|"\u003CCAEYMRowEZ3CLdTQKJU (48 more) ..."|0x702f2bd6
11:07:13.145 (145192000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
11:07:13.145 (145201000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
11:07:13.145 (145221000)|VARIABLE_ASSIGNMENT|[-1]|this.htmlBodyIsTruncated|false|0x702f2bd6
11:07:13.145 (145651000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
11:07:13.145 (145661000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
11:07:13.145 (145679000)|VARIABLE_ASSIGNMENT|[-1]|this.fromAddress|"test.processor+bncCO (36 more) ..."|0x5dee72ee
11:07:13.145 (145695000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:103
11:07:13.145 (145700000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
11:07:13.145 (145712000)|VARIABLE_ASSIGNMENT|[-1]|this.toAddress|"lead.saarm.processor (83 more) ..."|0x5dee72ee
11:07:13.146 (146435000)|EXECUTION_STARTED
11:07:13.146 (146447000)|CODE_UNIT_STARTED|[EXTERNAL]|01pD0000001EXM9|ProcessInboundEmail.handleInboundEmail
11:07:13.146 (146563000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1
11:07:13.146 (146583000)|METHOD_ENTRY|[6]|01pD0000001EXM9|ProcessInboundEmail.ProcessInboundEmail()

 

 

Here is some debug from the while loop, i have a feeling something is wrong here, as I see out of bound error, but can't point it out.

11:07:13.147 (147847000)|LIMIT_USAGE|[30]|SCRIPT_STATEMENTS|8|200000
11:07:13.147 (147861000)|VARIABLE_SCOPE_BEGIN|[30]|i|Integer|false|false
11:07:13.147 (147867000)|HEAP_ALLOCATE|[30]|Bytes:8
11:07:13.147 (147875000)|VARIABLE_ASSIGNMENT|[30]|i|0
11:07:13.147 (147912000)|SYSTEM_METHOD_ENTRY|[33]|LIST<String>.size()
11:07:13.147 (147951000)|SYSTEM_METHOD_EXIT|[33]|LIST<String>.size()
11:07:13.147 (147962000)|STATEMENT_EXECUTE|[33]
11:07:13.147 (147966000)|STATEMENT_EXECUTE|[34]
11:07:13.147 (147970000)|LIMIT_USAGE|[34]|SCRIPT_STATEMENTS|9|200000
11:07:13.147 (147984000)|HEAP_ALLOCATE|[34]|Bytes:26
11:07:13.147 (147996000)|HEAP_ALLOCATE|[34]|Bytes:1
11:07:13.148 (148042000)|HEAP_ALLOCATE|[34]|Bytes:12
11:07:13.148 (148049000)|HEAP_ALLOCATE|[34]|Bytes:1
11:07:13.148 (148061000)|HEAP_ALLOCATE|[34]|Bytes:37
11:07:13.148 (148085000)|VARIABLE_ASSIGNMENT|[34]|sourceText|["test.processor","optitex.com"]|0x14c8551b
11:07:13.148 (148094000)|STATEMENT_EXECUTE|[35]
11:07:13.148 (148098000)|LIMIT_USAGE|[35]|SCRIPT_STATEMENTS|10|200000
11:07:13.148 (148109000)|HEAP_ALLOCATE|[35]|Bytes:14
11:07:13.148 (148117000)|HEAP_ALLOCATE|[35]|Bytes:2
11:07:13.148 (148133000)|HEAP_ALLOCATE|[35]|Bytes:12
11:07:13.148 (148137000)|HEAP_ALLOCATE|[35]|Bytes:2
11:07:13.148 (148147000)|HEAP_ALLOCATE|[35]|Bytes:25
11:07:13.148 (148164000)|VARIABLE_ASSIGNMENT|[35]|mParams|["test","processor"]|0x43cf0468
11:07:13.148 (148175000)|HEAP_ALLOCATE|[37]|Bytes:4
11:07:13.148 (148182000)|HEAP_ALLOCATE|[37]|Bytes:4
11:07:13.148 (148215000)|STATEMENT_EXECUTE|[40]
11:07:13.148 (148220000)|LIMIT_USAGE|[40]|SCRIPT_STATEMENTS|11|200000
11:07:13.148 (148226000)|HEAP_ALLOCATE|[40]|Bytes:8
11:07:13.148 (148238000)|VARIABLE_ASSIGNMENT|[40]|i|1
11:07:13.148 (148258000)|SYSTEM_METHOD_ENTRY|[33]|LIST<String>.size()
11:07:13.148 (148270000)|SYSTEM_METHOD_EXIT|[33]|LIST<String>.size()
11:07:13.148 (148278000)|STATEMENT_EXECUTE|[33]
11:07:13.148 (148282000)|STATEMENT_EXECUTE|[34]
11:07:13.148 (148286000)|LIMIT_USAGE|[34]|SCRIPT_STATEMENTS|12|200000
11:07:13.148 (148368000)|HEAP_ALLOCATE|[34]|Bytes:31
11:07:13.148 (148405000)|VARIABLE_SCOPE_BEGIN|[64]|e|Exception|true|false
11:07:13.148 (148517000)|VARIABLE_ASSIGNMENT|[64]|e|"common.apex.runtime.impl.ExecutionException: List index out of bounds: 1"|0x74be13c9
11:07:13.148 (148527000)|STATEMENT_EXECUTE|[64]
11:07:13.148 (148532000)|STATEMENT_EXECUTE|[65]
11:07:13.148 (148536000)|LIMIT_USAGE|[65]|SCRIPT_STATEMENTS|13|200000
11:07:13.148 (148546000)|HEAP_ALLOCATE|[65]|Bytes:5
11:07:13.148 (148566000)|VARIABLE_ASSIGNMENT|[65]|this.success|false|0x10d7a7dd
11:07:13.148 (148573000)|STATEMENT_EXECUTE|[66]
11:07:13.148 (148576000)|LIMIT_USAGE|[66]|SCRIPT_STATEMENTS|14|200000
11:07:13.148 (148584000)|HEAP_ALLOCATE|[66]|Bytes:18