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
MDXHikerMDXHiker 

Developer Edition - pending commit

I am testing out functionality in dev edition where in an email is sent depending on some conditions in the Opp object. There is a trigger on the opp which then calls an apex class that send out the email.

 

I get the following in the debug logs 

 

Single email queued for send (pending commit)

 

and the email is not received at hte destination.

 

Why do I get this 'pending commit'  ? Are there any limitations in the dev edition?

 

Thanks

Message Edited by MDXHiker on 01-22-2009 02:52 PM
Best Answer chosen by Admin (Salesforce Developers) 
xtgjxtgj

Found a solution, really simple actually, problem was not visible by just outputting the emails with markers before and after like this.

 

If email was you@world.com and I did a System.debug('---'+email+'---'), output was

 

---you@world.com---

 

When I was getting emails from a multiline field, some whitespace sneaked in, but again, it doesn't show in the debugger window.

 

The way to detect the email was longer than it should be was to compare against a hardcoded version of the same email or by getting the length.

 

String hardcodedEmail = 'you@world.com';

email.equals( hardcodedEmail); <-- returned false

 

And with email.length() for the email I parsed out was just 1 longer, than the hardcoded version.

 

Solution was simple enough:

email = email.trim();

All Answers

MDXHikerMDXHiker

I do see in Apex Code Lang Ref the following statement.

 

'The email is not sent until the Apex transaction is committed'

 

How do I make sure the apex transaction commits? There are no inserts or updates in the apex code

SuperfellSuperfell
Then it commits or rolls back based on the containing operation. (how is your apex code being invoked?)
MDXHikerMDXHiker

I don't think the code ever commits. Or atleast I dont see it in the logs

The apex class is called by a trigger on Opp - after insert/update

 

thx

SuperfellSuperfell
whatever causes the trigger is controlling the transaction.
MDXHikerMDXHiker

The trigger is fired when the opp is edited and saved. I tried editing different fields in the Opp - all standard fields- but I still have the same problem.

The trigger is fired , the opp is saved properly with the new field values but the email does not go out due to 'pending commit' .

Any suggestions on how I can debug or resolve this? I am using the same code as in the API lang ref.

 

Thx

xtgjxtgj

I have same issue, and can see plenty others have same problem, and only non-helping answer is that the transaction is not commiting, but real question is why is it not commiting, new object is clearly saved successfully and trigger finishes.

 

My problem is for CaseComments, but seems issue is applicable to all SObjects.

 

 

I tried switching the event (after insert to before insert) in the hope that using before, the "insert" would maybe be the "commit" point.

 

I also logged the SendEmailResult and it returns "true". Hope someone know what is going on. 

xtgjxtgj

Don't know if this is only occuring for me.

 

But once I only sent to ONE email, it suddenly worked, so I started testing and found in order to send an email with two email addresses, I had to hardcode the emails into a String[] array (I was putting the emails into a List<String>).

 

So I changed from 

 

From

  List<String> emailAddresses  = ....

To

  String[] emailAddresses = new String[] { 'me@world.com', 'you@world.com'};

 

The Apex log for the email being sent is the same, no matter which way I did it.

   ... toAddresses: [me@world.com, you@world.com] 

 

 

 

 

But for some reason the outcome is different.

 

After some more testing I did not find full solution yet, as I still need to hardcode the array values

 

 

I tried generating the array from the List<String> I have with the emails, but no luck so far.

 

            String[] emailArray = new String[ emailAddresses.size()];
            Integer index = 0;
            for( String emailAddress : emailAddresses) {
                System.debug('case email: ---'+emailAddress +'---'); // here I verify I was getting the emails correctly.

                emailArray[index] = emailAddress;
                index++;
            }

 

 

Really strange, willl break for now and try again tomorrow,maybe someone else can use this information.

xtgjxtgj

Found a solution, really simple actually, problem was not visible by just outputting the emails with markers before and after like this.

 

If email was you@world.com and I did a System.debug('---'+email+'---'), output was

 

---you@world.com---

 

When I was getting emails from a multiline field, some whitespace sneaked in, but again, it doesn't show in the debugger window.

 

The way to detect the email was longer than it should be was to compare against a hardcoded version of the same email or by getting the length.

 

String hardcodedEmail = 'you@world.com';

email.equals( hardcodedEmail); <-- returned false

 

And with email.length() for the email I parsed out was just 1 longer, than the hardcoded version.

 

Solution was simple enough:

email = email.trim();

This was selected as the best answer