+ Start a Discussion
Nagaraj SVNagaraj SV 

unable to get code coverage

My apex class 
 
@RestResource(urlMapping='/SDUpdateSchoolService/*')
global with sharing class SD_UpdateSchoolService{
    @HttpPut
    global static deserializeResponse updateOrganization(){
        SD_UpdateSchoolService.deserializeResponse results;
        try{
            RestRequest req = RestContext.request;
            RestResponse res = RestContext.response;
            String jsonStr= req.requestBody.toString();    
            JSONParser parser = JSON.createParser(jsonStr);
            jsonParserClass UpdateOrganizationRequest = (jsonParserClass)parser.readValueAs(jsonParserClass.class);
            system.debug('UpdateOrganizationRequest=========>'+UpdateOrganizationRequest);
            if(UpdateOrganizationRequest.OrgId == null || UpdateOrganizationRequest.OrgId == ''){
                results = new SD_UpdateSchoolService.deserializeResponse(False, 'Please Send OrganizationId');
                return results;
            }else if(UpdateOrganizationRequest.OrgId != null){
                //Fetching the Profile/Contact information based on OrgId
                list<Account> lstAcc = [Select id from Account where Id =: UpdateOrganizationRequest.OrgId limit 1];
                if(lstAcc.size() > 0){
                    Account accobj = new Account();
                    accobj.id = UpdateOrganizationRequest.OrgId;
                    if(!String.isBlank(UpdateOrganizationRequest.SchoolName)){
                        accobj.Name = UpdateOrganizationRequest.SchoolName;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.addressline1)){
                        accobj.ShippingStreet = UpdateOrganizationRequest.addressline1 + UpdateOrganizationRequest.addressline2;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.City)){
                        accobj.ShippingCity = UpdateOrganizationRequest.City;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.State)){
                        accobj.ShippingState = UpdateOrganizationRequest.State;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.PostalCode)){
                        accobj.ShippingPostalCode = UpdateOrganizationRequest.PostalCode;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.Country)){
                        accobj.ShippingCountry = UpdateOrganizationRequest.Country;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.Fax)){
                        accobj.Fax = UpdateOrganizationRequest.Fax;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.Phone)){
                        accobj.Phone = UpdateOrganizationRequest.Phone;
                    }
                    if(!String.isBlank(UpdateOrganizationRequest.District)){
                        accobj.District__c = UpdateOrganizationRequest.District;
                    }
                   
                    update accobj;
                    results = new SD_UpdateSchoolService.deserializeResponse(True, 'Organization information Updated Successfully');
                    return results;
                }else{
                    results = new SD_UpdateSchoolService.deserializeResponse(False, 'Invalid Id was provided');
                    return results;
                } 
         }
            
        }catch (Exception ex) {
            string errorMessage = ex.getMessage(); 
            results=new SD_UpdateSchoolService.deserializeResponse(false, 'Error Message :'+errorMessage);
        }
        return results;
    }
    global class deserializeResponse{
        webservice Boolean Success {get; set;}
        webservice String  Message{get;set;}
        global deserializeResponse(Boolean success, String error){
            this.Success = success;
            this.Message = error;
        }
       
    }
   public class jsonParserClass{
        public String OrgId;
        public String UserId;
        public String SchoolName;
        public String addressline1;
        public String addressline2;
        public String City;
        public String State;
        public String PostalCode;
        public String Country;
        public String Phone;
        public String Fax;
        public String District;
   }
}

And Test Class is below and now coverage is 35% please help me and urgent 
 
@isTest
public class SD_UpdateSchoolServiceTest{
    static testMethod void updateSchoolServiceTest() {
        
        
        Account objAcc = new Account();
        objAcc.Name = 'Amoes';
        objAcc.ShippingStreet = '4 Fletcher St';
        objAcc.ShippingCity = 'Manchester';
        objAcc.ShippingState = 'NH';
        objAcc.ShippingPostalCode = '03086';
        objAcc.ShippingCountry = 'USA';
        objAcc.Website = 'http://www.amoskeagfishways.org';
        objAcc.KSD__TaxExemptId__c= '';
        objAcc.Description = 'Sampledesc';
        objAcc.KSD__Facebook__c= 'http://facebook.com/AmoskeagFishways';
        objAcc.Fax = '(603) 644-4386';
        objAcc.Phone = '9999999999'; 
        insert objAcc;
        
        Account objAccount = new Account();
        objAccount.ID = objAcc.Id;
        objAccount.Name = 'Amoes1123';
        objAccount.ShippingStreet = '4 Fletcher St';
        objAccount.ShippingCity = 'Manchester';
        objAccount.ShippingState = 'NH';
        objAccount.ShippingPostalCode = '03086';
        objAccount.ShippingCountry = 'USA';
        objAccount.Website = 'http://www.amoskeagfishways.org';
        objAccount.KSD__TaxExemptId__c= '';
        objAccount.Description = 'Sampledesc';
        objAccount.KSD__Facebook__c= 'http://facebook.com/AmoskeagFishways';
        objAccount.Fax = '(603) 644-4386';
        objAccount.Phone = '9999999999'; 
        Update objAccount;
        List<String> OrgId = new List<String>();
        OrgId.add(objAccount.ID);
        RestRequest req = new RestRequest(); 
        
        String JSONMsg = JSON.serialize(OrgId);
        req.httpMethod = 'PUT';
        req.requestBody = Blob.valueOf(JSONMsg);
        RestResponse res = new RestResponse();
        
        RestContext.request = req;
        RestContext.response = res;
        
        SD_UpdateSchoolService.deserializeResponse  SDUS = new SD_UpdateSchoolService.deserializeResponse(true,'OrgId');
        SDUS = SD_UpdateSchoolService.UpdateOrganization();
             
        
    }
    
}