• @rajeshdulhai
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 7
    Replies

Hi all,

 

i have an apex class ,

global class TwilioWeeklyScheduleSMS Implements Schedulable
{
    global void execute( SchedulableContext sc )
    {
        ScheduledSMS();
    }
    public void ScheduledSMS()
    {
        String message = 'SMS messages were sent to the following accounts:\n';
        
        List<Account> acc = [SELECT Id, Name, Mobile__c from Account where Weekly_Scheduled_SMS__c = true];
    
        if ( acc.isEmpty() ) return;
       
        Set<String> sendToPhones = new Set<String>();
    
        for ( Account a: acc )
        {
            sendToPhones.add( a.Mobile__c );
            message += a.Name + '\n';
        }    
        TwilioMessageHelper.sendSMSMessage( sendToPhones, 'Test SMS' );


        List<SMS_History__c> list_SMS_Histories = new List<SMS_History__c>();   
        for ( Account a: acc )
        {
            list_SMS_Histories.add
            (   new SMS_History__c
                (   Account__c          = a.Id,
                    Message__c          = 'Test SMS ',
                    Mobile_Number__c    = a.Mobile__c
                )
            );
        }
        insert list_SMS_Histories;
        Messaging.SingleEmailMessage emailMsg = new Messaging.SingleEmailMessage();
        emailMsg.setToAddresses( new List<String>{'rajesh.dulhani@nanostuffs.com' } );
        emailMsg.setSenderDisplayName( 'TwilioSchedule_Weekly_SMS' );
        emailMsg.setSubject( 'SMS Messages Sent' );
        emailMsg.setPlainTextBody( message );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { emailMsg } );
    }
}

 

 

 

i have written the following test code ,

@istest(seeAllData=false)
public class TestTwilioWeeklyScheduledSMS {
    private static testmethod void TestTwilioWeeklyScheduledSMS (){
    
        List<Account> acc = [SELECT Id, Name, Mobile__c from Account where Weekly_Scheduled_SMS__c = true];
        if ( acc.isEmpty() ) return;
       
        TwilioWeeklyScheduleSMS sms  = new TwilioWeeklyScheduleSMS ();
        sms.ScheduledSMS();
        
    }
}

 

i run this test it passed but still the code coverage is 0 % . What should i modify in this test class . please help

 

Thanks

Hi Everyone ,

 

 public static void ScheduledSMS()
{        
        List<Account> acc = [SELECT Id, Name, Mobile__c from Account where Weekly_Scheduled_SMS__c = true];
        if ( acc.isEmpty() )
        {           
            return;
        }
        integer count = 0;
        
        Set<String> sendToPhones = new Set<String>();
            
        for ( Account a: acc )
        {    
            sendToPhones.add(a.Mobile__c);
            TwilioMessageHelper.sendSMSMessage(sendToPhones,'Test SMS');
            SMS_History__c  smshistory = new SMS_History__c();
            smshistory.Account__c= a.Id;
            smshistory.Message__c  = 'Test SMS ';
            smshistory.Mobile_Number__c=a.Mobile__c;      
            insert smshistory ;
            ApexPages.AddMessage( new ApexPages.Message( ApexPages.Severity.INFO, ' SMS has been sent.'));  
        }
}

 

this is my apex class method . In this sendToPhones SET i am trying to add 10 mobile numbers at a time and hence it is giving error :

 

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

Error is in expression '{!ScheduledSMS}' in component <apex:page> in page testsendsms
 

can anyone help me with this code how to remove this error 

Hi everyone ,

 

i want to execute a scheduled job of sending sms . i am confused  in the code

 

my scheduled job code is as follows ,

 

global class TwilioSchedule_Weekly_SMS Implements Schedulable{
     global void Execute(SchedulableContext SC)
     {
          ScheduledSMS();
     }
     @future (callout=true) //code that does HTTP callouts
     static void ScheduledSMS(){
     
     QueryResult qResult = null;
     String soqlQuery = ' SELECT  Id ,Mobile__c  FROM Account WHERE Weekly_Scheduled_SMS__c = true ';
     qResult = connection.query(soqlQuery);
    
     TwilioMessageController obj = new  TwilioMessageController();
     obj.messageType = 'SMS ';
     obj.messageBody = ' test test ';
     obj.onSend();
     }
}

 

i want to select all the mobile nos from the above query and send SMS to all those numbers with the message body "test tes " . help me out in the code

 

Thanks ,

Rajesh

 

Hi everyone ,

 

i want to write a test class for the following apex class . Please help me 

 

APEX class:

 

public class ImportContactsController 
{

public blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvfilelines{get;set;}
public String[] inputvalues{get;set;}
public List<string> fieldList{get;set;}
public List<Account> sObjectList{get;set;}
public integer count =0;

 public void readcsvFile()
    { 
        csvFileLines = new String[]{}; 
        FieldList = new list<String>();
        sObjectList = new list<Account>();   
        csvAsString = csvFileBody.toString();
        csvfilelines = csvAsString.split('\n');
        inputvalues = new String[]{};
        for(string st:csvfilelines[0].split(',')) 
        FieldList.add(st);      
      
        for(Integer i=1;i<csvfilelines.size();i++)
        {
            Account obj = new Account() ;
            string[] csvRecordData = csvfilelines[i].split(',');
            obj.Name = csvRecordData[0];
            obj.Mobile__c = csvRecordData[1] ;             
            obj.Workshop_Number__c = csvRecordData[2] ;                                                 
            sObjectList.add(obj);   
        }  
                      
        Database.UpsertResult[] results = Database.upsert(sObjectList,Schema.Account.Workshop_Number__c, false);
        for (Database.UpsertResult res : results) 
        {
            if (res.isSuccess()) 
            {          
                count ++; 
            }
            else 
            {
                if (res.getErrors().size() > 0) 
                {
                     ApexPages.AddMessage( new ApexPages.Message( ApexPages.Severity.WARNING, ' ' +res.getErrors()[0].getMessage() ));
                }
            }          
        }
         ApexPages.AddMessage( new ApexPages.Message( ApexPages.Severity.INFO, +count+ ' Records Inserted ' ));         
    }
}

 

Please guide in writing a proper test class for this 

 

Thanks in advance 

 

i have deployed custom object from github . but that custom object is not visible under custom objects option . when i am trying to create object with the same name it gives error that object is already present but its not visible how do i make it visible i tried the profiles option

please help me

 

Thanks