You need to sign in to do that
Don't have an account?
sree prasad
hello please help for the test class
public class OfficedataSync {
public List<officewrap> myd{get;set;}
public string searchStr {get; set;}
public string searchStrfrm {get; set;}
public void getperformcallout(){
myd = new List<officewrap>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
String url='https://mail.google.com/mail/u/0/#inbox/FMfcgxvzLDrvZsWbCZhTnVxCtDRwNjNv'
req.setEndpoint(url);
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
try{
myd=(List<officewrap>)json.deserialize(res.getbody(),List<officewrap>.class);
list<Lead> ld= new list<Lead>();
for (Integer i = 0; i < myd.size(); i++) {
ld = [select id from Lead where office_lead_id__c LIKE :myd[i].call_id+'%' ];
if(ld.size()==0){
Lead lstLead = new Lead();
lstLead.office_lead_id__c=myd[i].call_id;
lstLead.LastName=myd[i].phone_number;
insert lstLead;
}
}
}catch(Exception ex){
myd=null;
}
public List<officewrap> myd{get;set;}
public string searchStr {get; set;}
public string searchStrfrm {get; set;}
public void getperformcallout(){
myd = new List<officewrap>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
String url='https://mail.google.com/mail/u/0/#inbox/FMfcgxvzLDrvZsWbCZhTnVxCtDRwNjNv'
req.setEndpoint(url);
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
try{
myd=(List<officewrap>)json.deserialize(res.getbody(),List<officewrap>.class);
list<Lead> ld= new list<Lead>();
for (Integer i = 0; i < myd.size(); i++) {
ld = [select id from Lead where office_lead_id__c LIKE :myd[i].call_id+'%' ];
if(ld.size()==0){
Lead lstLead = new Lead();
lstLead.office_lead_id__c=myd[i].call_id;
lstLead.LastName=myd[i].phone_number;
insert lstLead;
}
}
}catch(Exception ex){
myd=null;
}
Step 1 : create a mock response for test class .. .pls set the json body for the test class ..
Test Class
Invalid type: OfficedataSyncMock
private class OfficedataSync_test {
private class Office24by7Mock implements HttpCalloutMock {
public HTTPResponse respond(HTTPRequest req) {
String ofcjsondata = '[{Give your url or json data Format}]';
HTTPResponse res = new HTTPResponse();
res.setHeader('Content-Type', 'text/json');
res.setBody(ofcjsondata);
res.setStatusCode(200);
return res;
}
}
static testMethod void office_service_call() {
Test.setMock(HttpCalloutMock.class, new Office24by7Mock());
Test.startTest();
OfficedataSync obj=new OfficedataSync();
officewrap s=new officewrap();
obj.getperformcallout();
Test.StopTest();
}
}