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

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

hi all,

I am facing error: You have uncommitted work pending. Please commit or rollback before calling out and i have used @future(callout = true) method it is not working can anyone help me with these

Apex Class:
public class Campaignbulk {
    public campaign camp;
    public integer cnt{get;set;}
    public string Text {get;set;}
    Public list<Campaignmember> camplist=new list<Campaignmember>();
    public list<Campaign> listcamp =new list<Campaign>();
    public Campaignbulk (ApexPages.StandardController stdController)
    { =(Campaign)stdController.getRecord(); 
        cnt=[ SELECT count() FROM Campaignmember WHERE CampaignId =:camp.Id];   
        camplist=[ SELECT phone FROM Campaignmember WHERE CampaignId =:camp.Id];  
    public  void sendbulk(){
        List<SMS_Response__c> responseList= new List <SMS_Response__c>();
        for(Campaignmember Cpgmb: camplist ) {
            SMS_Response__c NewRec = new SMS_Response__c();
            NewRec.Mobile_Number__c =Cpgmb.Phone ;
            NewRec.Message__c = Text;
            NewRec.SMS_Type__c = 'OutGoing Message' ;
            NewRec.Service_Providers__c = 'Nexmo'; 
        if (responseList.size()>0)
        processCampaign(camp.Id, Text);
    public static void processCampaign(string campaignID, String smsText){
        configuration_setting__c conf = [select Name, Phone_Numbers__c,Lead_Phone_Number__c 
                                         FROM configuration_setting__c where Active__c =True  limit 1 ];                     
        List<String> lstAlpha = conf.Phone_Numbers__c.split(',');
        Integer currentPhone=0;
        List<Campaignmember> camplist=[ SELECT phone FROM Campaignmember WHERE CampaignId =:campaignID];
        for(Campaignmember Cpgmb: camplist ) {
            String newStatus= Nexmo.bulksms(  Cpgmb.Phone,  lstAlpha[currentPhone++],  smsText, 'sms');
            if (currentPhone >= lstAlpha.size()){
        } // end of all campaing memebers 
    } // end of method
    Public static void insertstatus(string campaignID,string Cpgmbphone,string newStatus){
         List<SMS_Response__c> smsRespList = [select id, status__c from SMS_Response__c where Campaign__c=:campaignID
                                                 and status__c='Processing' 
                                                 and Mobile_Number__c =:Cpgmbphone];
            if (smsRespList!= null && smsRespList.size()>0 ) {
                for(SMS_Response__c smsrp:smsRespList){
                    smsrp.status__c =newStatus;
                system.debug('My updated list'+smsRespList);
                 update smsRespList;

Raghu NaniRaghu Nani
Hi Nihar,

Is this Campaignbulk class been reffering in VF Page, If yes, please 
follow this link:

skype: raghup101