-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
13Questions
-
7Replies
Help for writing test class
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
-
- @rajeshdulhai
- December 12, 2013
- Like
- 0
- Continue reading or reply
Help Regarding Error
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
can anyone help me with this code how to remove this error
-
- @rajeshdulhai
- December 12, 2013
- Like
- 0
- Continue reading or reply
Sending Bulk SMS
Hi all,
I want to send bulk sms to all the accounts using scheduled job using the custom field Mobile__c from the account . This custom field contains the mobile number to whom the sms is to be sent . same message body is to be sent to all the accounts at a time . How can i achieve this please help
Thanks ,
Rajesh
-
- @rajeshdulhai
- December 11, 2013
- Like
- 0
- Continue reading or reply
sending single email to salesforce through scheduled job
Hi everyone ,
This is scheduled job code ,
global class TwilioSchedule_Weekly_SMS Implements Schedulable{
global void Execute(SchedulableContext SC)
{
ScheduledSMS();
}
static void ScheduledSMS()
{
List<Account> acc = [SELECT Id, Mobile__c from Account where Weekly_Scheduled_SMS__c = true];
if(acc.size() != 0){
for(Account a: acc){
TwilioMessageController obj = new TwilioMessageController();
obj.messageBody = 'test test ';
obj.WhoId = a.Id;
obj.sendToPhones.add(a.Mobile__c);
obj.onSend();
}
}
}
}
in this code i am sending sending sms to the accounts on scheduled basis . After the sms is sent i want to send an email on the particular email address with the name of the all the accounts to whom the SMS is sent saying that SMS to all the accounts were sent successfully
Thanks ,
Rajesh
-
- @rajeshdulhai
- December 10, 2013
- Like
- 0
- Continue reading or reply
Regarding Scheduled job
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
-
- @rajeshdulhai
- December 09, 2013
- Like
- 0
- Continue reading or reply
Help for writing a test class for APEX class
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
-
- @rajeshdulhai
- December 05, 2013
- Like
- 0
- Continue reading or reply
I am having error while import contacts from csv file
Apex code :
public with sharing class FileUploader
{
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<TwilioImportObject__c> accstoupload;
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<TwilioImportObject__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
TwilioImportObject__c a = new TwilioImportObject__c();
a.Name__c = inputvalues[0];
a.Mobile_Number__c = inputvalues[1];
a.Workshop_Number__c= inputvalues[2];
accstoupload.add(a);
}
try{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}
return null;
}
public List<TwilioImportObject__c> getuploadedAccounts()
{
if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;
else
return null;
else
return null;
}
}
Visualforce code :
<apex:page sidebar="false" controller="FileUploader">
<apex:form >
<apex:sectionHeader title="Upload data from CSV file"/>
<apex:pagemessages />
<apex:pageBlock >
<center>
<apex:inputFile value="{!contentFile}" filename="{!nameFile}" /> <apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;"/>
<!-- <br/> <br/> <font color="red"> <b>Note: Please use the standard template to upload Accounts. <a href="{!URLFOR($Resource.AccountUploadTemplate)}" target="_blank"> Click here </a> to download the template. </b> </font>-->
</center>
<apex:pageblocktable value="{!uploadedAccounts}" var="acc" rendered="{!NOT(ISNULL(uploadedAccounts))}">
<apex:column headerValue=" Name">
<apex:outputField value="{!acc.Name__c}"/>
</apex:column>
<apex:column headerValue="Mobile number">
<apex:outputField value="{!acc.Mobile_Number__c}"/>
</apex:column>
<apex:column headerValue="Workshop No">
<apex:outputField value="{!acc.Workshop_Number__c}"/>
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
contents of csv file
NAME MOBILENUMBER WorkshopNo
rajesh 9850432340 1001
girish 8451254565 1002
akash 8478589698 1003
while clicking on upload button its giving error
System.StringException: BLOB is not a valid UTF-8 string
Class.FileUploader.ReadFile: line 10, column 1
please help me in correcting the code . i hope everything is clear
Thanks
-
- @rajeshdulhai
- November 30, 2013
- Like
- 0
- Continue reading or reply
Regarding Custom Object
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
-
- @rajeshdulhai
- November 29, 2013
- Like
- 0
- Continue reading or reply
Regarding search query
I am new to salesforce . i want to search all the fields related to custom object (Candidate__c ) by using search keyword
This is my search controller code
public with sharing class searchcontroller{
public String mysearchtext {get; set;}
public void dosearch()
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'My Search Text : ' + (mysearchtext));
apexpages.addmessage(msg);
//***** search logic ****//
}
}
please help me with the code
Thanks in advance
-
- @rajeshdulhai
- November 21, 2013
- Like
- 0
- Continue reading or reply
How to give action to custom button to go on new visualforce page
i have 2 visualforce pages . one is for displaying records and another for creating records . On displaying records pages i have a button named creating new record . onclick of this button i want to redirect this page to creating records page
please help me in code for apex controller
thanks in advance
-
- @rajeshdulhai
- November 19, 2013
- Like
- 0
- Continue reading or reply
how to show the page is loading on the click of the button in visualforce
i have four tabs developed on my visualforce page with two buttons on each page i.e previous and next button . i want to have a functionality on click of previous and next button to show the user that the page is loading until the page is fully loaded . how can this be done ?
Thanks in advance
-
- @rajeshdulhai
- November 15, 2013
- Like
- 0
- Continue reading or reply
Regarding Visualforce page help
Hi ,
I want to develop a visualforce page in which i want to retrieve the values of the standard object (opportunity ) and display in web form . By using which commands i can do this ?
please help
Thanks
-
- @rajeshdulhai
- November 01, 2013
- Like
- 0
- Continue reading or reply
Regarding standard objects present under customize options
I have started learning salesforce past 15 days . I referred force.com workbook . Now I am able to build custom objects , fields , relationships between objects page layouts . I want the material in which the information regarding standard objects such as ACCOUNTS , LEADS , CONTACTS , OPPORTUNITIES etc is provided . Please help me
Thanks in advance
-
- @rajeshdulhai
- October 24, 2013
- Like
- 0
- Continue reading or reply
Help for writing test class
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
- @rajeshdulhai
- December 12, 2013
- Like
- 0
- Continue reading or reply
Help Regarding Error
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
can anyone help me with this code how to remove this error
- @rajeshdulhai
- December 12, 2013
- Like
- 0
- Continue reading or reply
Regarding Scheduled job
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
- @rajeshdulhai
- December 09, 2013
- Like
- 0
- Continue reading or reply
Help for writing a test class for APEX class
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
- @rajeshdulhai
- December 05, 2013
- Like
- 0
- Continue reading or reply
Regarding Custom Object
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
- @rajeshdulhai
- November 29, 2013
- Like
- 0
- Continue reading or reply