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
rohit singh 92rohit singh 92 

how can i create test function for the following .. please help in this.. i tried many ways but didnt worked .. please help !

public Pagereference VerifySingleContact()
    {
        
        String SignleContactlicenseKey = '34f059d1-d6d3-4be0-a592-3ac254faa34c';
        String SignleContactVerify =  'https://api.accurateappend.com/Services/V2/AppendPhone/Residential/'+ SignleContactlicenseKey + '/?';
        String SignleContactVerifyQueryString = 'firstname='+EncodingUtil.urlEncode(firstname, 'UTF-8')+
               '&lastname='+EncodingUtil.urlEncode(lastname, 'UTF-8')+
               '&address='+EncodingUtil.urlEncode(useraddress, 'UTF-8')+
               '&city='+EncodingUtil.urlEncode(usercity, 'UTF-8')+
               '&state='+EncodingUtil.urlEncode(userstate, 'UTF-8')+
               '&postalcode='+EncodingUtil.urlEncode(userpostalcode, 'UTF-8')+
               '&source=C;D;M' +
               '&matchlevel=E1;E2;N1;N2';
        String url =  SignleContactVerify  + SignleContactVerifyQueryString ;
        String AccurateResponse;
        String log;
        //query string end
        accstoupload = new List<Contact>();
    
        // Instantiate a new http object
        Http h = new Http();
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('GET');
        // Send the request, and return a response
        HttpResponse res = h.send(req);
        //return res.getBody();
        AccurateResponse = res.getBody();
        JSONParser parser = JSON.createParser(AccurateResponse);
        JSON2Apex jtop = JSON2Apex.parse(AccurateResponse);
        parser.nextToken();
        parser.nextValue();
        
        if(parser.getCurrentName()=='Criteria')
        {
            String PhoneList = '' ;
           // my code
            Phones = JSON.serialize(jtop.Phones);
            JSON2Apex phoneListing = (JSON2Apex)JSON.deserialize(AccurateResponse, JSON2Apex.class);
            for(Integer k = 0;k<phoneListing.Phones.size();k++)
            {
                PhoneList +=    '('+phoneListing.Phones[k].AreaCode+')'+ phoneListing.Phones[k].PhoneNumber + ',';
            }
           // my code           
                Account acc = new Account(Name = 'Robert L Knox');
                Contact a = new Contact();
                a.FirstName = firstname ;
                a.LastName = lastname ;
                a.AccountId = acc.Id;
                a.Phone = PhoneList;
                a.MailingStreet = useraddress;
                a.MailingCity = usercity;
                a.MailingState = userstate;
                a.MailingCountry = '';
                a.MailingPostalCode = userpostalcode;
                a.accurateAppendVerified__c = true;
                accstoupload.add(a);
            
            try{
              insert accstoupload;
            }
            catch (Exception e)
            {
                ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured inserting the records'+e.getMessage());
                ApexPages.addMessage(errormsg);
            }
        }else
        {
            Account acc = new Account(Name = 'Robert L Knox');
            Contact a = new Contact();
            a.FirstName = firstname ;
            a.LastName = lastname ;
            a.AccountId = a.Id;
            a.accurateAppendVerified__c = false;
            accstoupload.add(a);
        }
        
               
        return null;
    }

 
rohit singh 92rohit singh 92
it just says no web callout in test class .. please help me in creating test functioning for ths