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
sree prasadsree 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;

}
Raj VakatiRaj Vakati
Try this code
Step 1 : create a mock response for test class .. .pls set the json body for the test class .. 
 
global class OfficedataSyncMock implements HttpCalloutMock {

    global HTTPResponse respond(HTTPRequest request) {

        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('{}');
        response.setStatusCode(200);
        return response; 

    }

}



Test Class
 
@isTest Public class OfficedataSynTest{

    Public Static testmethod void mytest()

    {  
        Test.setMock(HttpCalloutMock.class, new OfficedataSyncMock()); 

        HttpResponse  response = New HttpResponse ();
        System.Test.startTest();
        OfficedataSync  ooo = new OfficedataSync() ;
		ooo.getperformcallout();
		
        System.Test.stopTest();



    }

	


}

 
sree prasadsree prasad
Am getting this Error

Invalid type: OfficedataSyncMock
Raj VakatiRaj Vakati
Did you create OfficedataSyncMock  apex class also .. first you need to create "OfficedataSyncMock " apex class with mock test data then call it in test class 
sree prasadsree prasad
@isTest 
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();


    }
}