In my previous posts I have reported an issue which yields

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

exception where it should not arise.

First time I reported this was at February 12, 2015, later on November 9, 2016 I have noted that the corresponding known issue was marked as resolved but the actual problem wasn’t solved, also on December 1, 2016 I have suggested a workaround to this bug.

As of Summer 2019 (v.46), I can confirm that this particular bug seems to be resolved.

However, another bug has arised recently.

To reproduce it, a dummy batch class is needed.


public class b implements Database.Batchable<SObject>,Database.AllowsCallouts{
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT id FROM user WHERE IsActive=true limit 1');
}
public void execute(Database.BatchableContext bc, List<User> users) {
new Http().send(new HttpRequest());
}
public void finish(Database.BatchableContext bc) {}
}

 


@isTest class TOTTest {
private static final Integer STATUS_CODE_200 = 200;
private static final String STATUS_OK = 'OK';
private static final String SUCCESS_RESPONSE = '{"response":{"metadata":[{"totalrowcount":1},{"rendertime":0}]}}';

public class q implements Queueable,Database.AllowsCallouts{
public void execute(QueueableContext context) {
new Http().send(new HttpRequest());
}
}

private static testMethod void testQ() {
insertData();
Test.startTest();
Test.setMock(HttpCalloutMock.class, new MockHttpResponse());
System.enqueueJob(new q());
Test.stopTest();

}

private static testMethod void testB() {
insertData();
Test.startTest();
Test.setMock(HttpCalloutMock.class, new MockHttpResponse());
Database.executeBatch(new b());
Test.stopTest();

}

static void insertData() {
//insert new Test_Object__c();

insert new User(
Username='julfy@i.ua',
LastName='D',
Email='julfy@i.ua',
Alias='D',
CommunityNickname='D',
TimeZoneSidKey='America/Los_Angeles',
LocaleSidKey='en_US',
EmailEncodingKey='ISO-8859-1',
ProfileId=UserInfo.getProfileId(),//'00eE0000000z6DLIAY'
LanguageLocaleKey='en_US'
);
}
}

This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to

  1. Mo Ham says:

    Do you have a possible workaround for this issue?

  2. CoreyY says:

    The ‘new bug’ you describe above in v46.0 of the API seems to be this one which has come back (meant to have been solved in Spring ’16 Patch 2.0):

    https://success.salesforce.com/issues_view?id=a1p30000000jbNMAAY

    Has it been reported to Salesforce again?

  3. patlatus says:

    Yes, I have reported this to Salesforce. https://patlatus.wordpress.com/2019/08/06/salesforce-bug-in-tests-system-calloutexception-you-have-uncommitted-work-pending-please-commit-or-rollback-before-calling-out/ They had been investigating this issue for a month before I got a response with link to known issue or salesforce internal issue tracking number.
    My case number was 23600897, I have opened this case on the July 10th. I received a link to a known issue https://success.salesforce.com/issues_view?id=a1p3A000000ATF1QAO and internal salesforce issue tracking number W-4947848 on August 8th, however, I am not sure if this is the same issue as I have since that issue doesn’t have a workaround and for my case I have a workaround.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s