You need to sign in to do that
Don't have an account?
Rajesh SFDC
how to write test class using webservice.
global class CampaignReminder
{
WebService static void SendReminder(string id)
{
id cmpid = id;
Integer batchSize = 1;
database.executebatch(new SendeMailinBatch(cmpid) , batchSize);
}
}
=================batch process====
global class SendeMailinBatch implements Database.Batchable<sObject>,Database.Stateful
{
Public id campaignid;
global SendeMailinBatch(id campid)
{
campaignid = campid;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
//Batch on all campaign memeber who belongs to the requetsed campaign
String query = 'select id, emailtobesentid__c from campaignmember where campaignid = :campaignid';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
//*** Select the campaign details
List<campaignmember> cmx = new list<campaignmember>();
campaign cmp = new campaign();
cmp = [ select id, From_eMail__c, Reply_To__c, templatetobesent__c from campaign where id = :campaignid ];
for(Sobject s : scope)
{
//Type cast sObject in campaign object
campaignmember CM = (campaignmember)s ;
//Sending Mail
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSenderDisplayName(cmp.From_eMail__c);
mail.setReplyTo(cmp.Reply_To__c);
mail.setTargetObjectId(CM.emailtobesentid__c);
mail.setTemplateId(cmp.templatetobesent__c);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
global void finish(Database.BatchableContext BC)
{
}
}
{
WebService static void SendReminder(string id)
{
id cmpid = id;
Integer batchSize = 1;
database.executebatch(new SendeMailinBatch(cmpid) , batchSize);
}
}
=================batch process====
global class SendeMailinBatch implements Database.Batchable<sObject>,Database.Stateful
{
Public id campaignid;
global SendeMailinBatch(id campid)
{
campaignid = campid;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
//Batch on all campaign memeber who belongs to the requetsed campaign
String query = 'select id, emailtobesentid__c from campaignmember where campaignid = :campaignid';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
//*** Select the campaign details
List<campaignmember> cmx = new list<campaignmember>();
campaign cmp = new campaign();
cmp = [ select id, From_eMail__c, Reply_To__c, templatetobesent__c from campaign where id = :campaignid ];
for(Sobject s : scope)
{
//Type cast sObject in campaign object
campaignmember CM = (campaignmember)s ;
//Sending Mail
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSenderDisplayName(cmp.From_eMail__c);
mail.setReplyTo(cmp.Reply_To__c);
mail.setTargetObjectId(CM.emailtobesentid__c);
mail.setTemplateId(cmp.templatetobesent__c);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
global void finish(Database.BatchableContext BC)
{
}
}
Apex provides the built-in WebServiceMock interface and the Test.setMock method that you can use to receive fake responses in a test method to test webservice callout.
Please refer following help document for sample code:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008z4VIAQ