You need to sign in to do that
Don't have an account?
Rajendra Prasad 44
and when I remove emailmessage record insertion part its working. but I need that
can anyone help me with this test class
@isTest public class TestDataFactory { public static testMethod void testdata_for_manipulateDataForInviteBlast(){ insert new Pardot_Settings__c(Name = 'Pardot User Key', User_Key__c ='xxxxxxxxxxxxxxxxxxx'); Test.setMock(HttpCalloutMock.class, new MockHttpResponseGeneratorpost()); Account a = new Account(); a.Name = 'Test Account'; Insert a; Contact con1 = new Contact(); con1.FirstName='Seema'; con1.LastName= 'singh'; con1.AccountId = a.Id; con1.Email='seemax1.singh@accelerize360.com'; insert con1; Analyst__c an= new Analyst__c(); an.Name='asdf122345'; an.Order_of_Precedence__c = '1'; insert an; Custom_Event__c cEvent = new Custom_Event__c(); cEvent.name = 'testingEvent'; cEvent.CAT_external_event_name__c = 'testing External Event'; cEvent.Type_of_Meeting__c = 'Analyst Marketing'; cEvent.Start_Date__c = DateTime.Now().AddDays(10); cEvent.End_Date__c = DateTime.Now().AddDays(13); insert cEvent; Campaign com = new Campaign(); com.Analyst__c=an.id; com.Related_Event__c = cEvent.Id; com.Name='test'; insert com; CampaignMember cm = new CampaignMember(); cm.ContactId=con1.id; cm.CampaignId=com.id; cm.CampaignId = com.id; insert cm; EmailMessage incomingMail = new EmailMessage(); incomingMail.fromaddress='test@email.com'; incomingMail.toAddress = 'test@test.com'; incomingMail.subject = ' Test Message'; incomingMail.TextBody= 'This is the message body '; incomingMail.RelatedToId = cEvent.id; insert incomingMail ; } }
here I'm not testing integration directly, but it was like whenever contact is created it happens, so its making callout indirectly that's why I have to use more class.
here when I run the test I'm getting error:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
and when I remove emailmessage record insertion part its working. but I need that
GetEmailInfoWrapper :
ManipulateDataToSendEmail :
Move this Test.setMock(HttpCalloutMock.class, new MockHttpResponseGeneratorpost()); to after the last DML statement and then run it. It should work as you never call a callout before DML you neeed to call out after the last DML.
Let me know the results please.
Thanks