• ganesh jadhav
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies

Hi I'm trying to write test cases using isTest annotation

first of all i have initialized my visualforce page.

than initialized the controller

and iam calling each methods in controller

 

but in my code coverage is only 76% only....... i know 75% code coverage is enough for deploy code in production organization but iam expecting 100% code coverage here is my code please let me any suggesions

 

Here is mine Controller

in mine controller logic is reda csv file and display in to some vf page

 

//Create Controller For Import CSV File and Insert itnto Database
public class CSVcontroller {    
    public Blob uploadFile{ get; set; }
    public String nameFile { get; set; }
    public Integer colCount { get; set; }
    public String row {get; set;}
    public Integer rowCount { get; set; }
    public String fileString { get; set; }    
    //Insert Action for inserting the csv data into Fund_Management object
    @RemoteAction
    public static void insertAccounts(List<Fund_Management__c> fundlist){                 
        try{
            //Schema.DescribeFieldResult fId = Fund_Management__c.fnameMonthYear__c.getDescribe();
            //Schema.sObjectField T = fId.getSObjectField();
            Schema.SObjectField fId = Fund_Management__c.Fields.fnameMonthYear__c;
            //upsert(fundlist,fId,false);
            //insert fundlist;            
            //Database.Upsert(fundlist,fId,false);
              upsert fundlist fnameMonthYear__c;                      
            }catch(DmlException e) {
                System.debug('An unexpected error has occurred: ' + e.getMessage());
            }
       }
    
    public List<List<String>> getResults() {        
       List<List<String>> parsedCSV = new List<List<String>>();
       rowCount = 0;
       colCount = 0;
       if (uploadFile!= null){
            fileString = uploadFile.toString();       
            parsedCSV = parseCSV(fileString, false);
            rowCount = parsedCSV.size();
            for (List<String> row : parsedCSV){
               if (row.size() > colCount){
               colCount = row.size();
               }
            }
       }
       System.debug('nameFile' + nameFile);
       return parsedCSV;
     }
     public static List<List<String>> parseCSV(String contents,Boolean skipHeaders) {
         List<List<String>> allFields = new List<List<String>>();
         // replace instances where a double quote begins a field containing a comma
         // in this case you get a double quote followed by a doubled double quote
         // do this for beginning and end of a field
         contents = contents.replaceAll(',"""',',"DBLQT').replaceall('""",','DBLQT",');
         // now replace all remaining double quotes - we do this so that we can reconstruct
         // fields with commas inside assuming they begin and end with a double quote
         contents = contents.replaceAll('""','');
         // we are not attempting to handle fields with a newline inside of them
         // so, split on newline to get the spreadsheet rows
         List<String> lines = new List<String>();
         try {
         lines = contents.split('\r'); // using carriage return accomodates windows, unix, and mac files
         }
         catch (System.ListException e) {
         System.debug('Limits exceeded?' + e.getMessage());
         }
         Integer num = 0;
         for(String line: lines){
             // check for blank CSV lines (only commas)
             if (line.replaceAll(',','"').trim().length() == 0) break;
                 List<String> fields = line.split(',');
                 List<String> cleanFields = new List<String>();
                 System.debug('fields' + fields );
                 String compositeField;
                 Boolean makeCompositeField = false;
     
                 for(String field: fields) {
                     if (field.startsWith('"') && field.endsWith('"')) {
                     cleanFields.add(field.replaceAll('DBLQT',''));
                     }
                     else if (field.startsWith('"')) {
                     makeCompositeField = true;
                     compositeField = field;
                     }
                     else if (field.endsWith('"')) {
                     compositeField += ',' + field;
                     cleanFields.add(compositeField.replaceAll('DBLQT',''));
                     makeCompositeField = false;
                     }
                     else if (makeCompositeField){
                     compositeField +=  ',' + field;
                     }
                     else {
                     cleanFields.add(field.replaceAll('',''));
                     }
                }
                allFields.add(cleanFields);
            }
        //if (skipHeaders) allFields.remove(0);
        return allFields;     
     }
    public void checkblankfile(){
        if(rowCount == 0) {
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'The file is empty.'));
        }        
     }
    public PageReference vfReciredt(){         
        if(uploadFile ==null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Upload File'));
        }
        else{
            //PageReference redirect = new PageReference('/apex/Fund_List?sfdc.tabName=01r900000007xyR');
            //redirect.setRedirect(true);
            //return redirect;
        }
        return null;
    }

}

 

 highlighted area is not get covered anybody knows to get code coverage for that area..... and also let me know how to increase code coverage for code included in conditional statements like  for, if, else conditions

 

and here is mine Test class

 

@isTest
private class csvControllerTest
{    
   static testMethod void myUnitTest() {
        
        //Test converage for the cumulativePerformanceChart visualforce page        
        PageReference pageRef = Page.ImportCSV;
        Test.setCurrentPageReference(pageRef);          
        // Perform our data preparation.
        //Insert Single Record
        Fund_Management__c fmssr = new Fund_Management__c(Fund_Name__c='test fund',Growth__c=1.2,Month__c='Jan',Year__c=2008);
        insert fmssr;
        //Insert Bulk Record
        List<Fund_Management__c> fmsbr = new List<Fund_Management__c>{};
                 
        for(Integer i = 0; i < 200; i++){
            Fund_Management__c f = new Fund_Management__c(Fund_Name__c = 'Test Fund '+i,Growth__c = 1.2,Month__c = 'Jan',Year__c = 2008);
            fmsbr.add(f);
        }        
         //Now insert data causing an contact trigger to fire.
        Test.startTest();
        try {
             insert fmsbr;        
        }catch(DmlException e) {
           
            }       
        Test.stopTest();       
        // Query the database for the newly inserted records.
        List<Fund_Management__c> insertedFunds = [SELECT Fund_Name__c, Growth__c ,Month__c,Year__c FROM Fund_Management__c];             
        // Assert that the Description fields contains the proper value now.
        for(Fund_Management__c a : insertedFunds){
        System.assert(insertedFunds != null);
        }        
    
        String csvContent = 'Test,Jan,2001,3,l\nTest1,Feb,2001,4,k';
        //initialization of csvcontroller
        CSVcontroller csv = new CSVcontroller();
        List<List<String>> parsedCSV = CSVcontroller.parseCSV(csvContent,false);
        system.assertEquals(parsedCSV[0][0],'Test');
        system.assertEquals('Jan',parsedCSV[0][1]);
        system.assertEquals('2001',parsedCSV[0][2]);
        system.assertEquals('3',parsedCSV[0][3]);
        //Call All Methods In CsvController
         csv.getResults();
         csv.vfReciredt();
         csv.checkblankfile();           
         CSVcontroller.insertAccounts(fmsbr);
    }
}

 

in that i have write the insert logic for 1 records and insert logic for 200 records still not getting 100 % code coverage

Hi I'm trying to write test cases using isTest annotation

first of all i have initialized my visualforce page.

than initialized the controller

and iam calling each methods in controller

 

but in my code coverage is only 85% only....... i know 75% code coverage is enough for deploy code in production organization but iam expecting 100% code coverage here is my code please let me any suggesions

 

Here is mine Controller

 

   public class MyQueryController{

   public Set<String>myQueryResults { get; Public set; }  

   public List<Fund_Management__c> getUniquedata(){

   myQueryResults= new Set<String>();  

    List<Fund_Management__c> query=[SELECT Fund_Name__c FROM Fund_Management__c];

    System.debug('Results'+query);  9    for(Fund_Management__c results : query){  

    myQueryResults.add(results.Fund_Name__c); 

   }  

    return query;

    }  

  }

 

highlighted area is not get covered anybody knows to get code coverage for that area..... and also let me know how to increase code coverage for code included in conditional statements like  for, if, else conditions

 

 

 

And here is mine test class

 

@isTest
Private class MyQueryControllerTest{
    Static testmethod void UnitTest(){
    Set<String> myQueryResults = new Set<String>{};
    List<Fund_Management__c> query=[SELECT Fund_Name__c FROM Fund_Management__c];
    //initialized the vf page here
    PageReference pageref = Page.MyQueryPage;
    Test.setCurrentPageReference(pageref);
    //initialized the controller
    MyQueryController myqc = new MyQueryController();
    //calling methods in controller
    myqc.getUniquedata();
    }
}

 

hi iam new in salesforce.com,

i have to create webservice for inserting one record in my custom object, i cant able to generate WSDL  plz help me .....

i have creted class, hit the generate from wsdl still not working

 

I am trying to Run Schedule job........but Schedulable class has jobs pending or in progress? This Error is occurs again and again, i have deleted the scheduler class and tried again still same problem occurs if have any suggetions please let me know...... here is my scheduler class for send Emails to employee on his birth day :-

 

global class BirthdayMailSend implements Schedulable
{
    global void execute (SchedulableContext ctx)
    {
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
    for ( Employee__c emp : [SELECT Id, Name,email__c,First_Name__c FROM Employee__c WHERE Birth_date__c = TODAY] )
    {
     mail.setSubject('New Employee Record Created..!');
     mail.setHtmlBody('Hello'+emp.First_Name__c+'!<br/>today is your birth day bhikarya cake kap nahi tar muskadin');
     mail.setToAddresses(new String[] {emp.email__c});
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });        
    }
    BirthdayMailSend mc = new BirthdayMailSend();
    String sch = '0 0,1 * * * *';
    system.schedule('Birthdaymail', sch, mc);
    }
}

Hi I'm trying to write test cases using isTest annotation

first of all i have initialized my visualforce page.

than initialized the controller

and iam calling each methods in controller

 

but in my code coverage is only 76% only....... i know 75% code coverage is enough for deploy code in production organization but iam expecting 100% code coverage here is my code please let me any suggesions

 

Here is mine Controller

in mine controller logic is reda csv file and display in to some vf page

 

//Create Controller For Import CSV File and Insert itnto Database
public class CSVcontroller {    
    public Blob uploadFile{ get; set; }
    public String nameFile { get; set; }
    public Integer colCount { get; set; }
    public String row {get; set;}
    public Integer rowCount { get; set; }
    public String fileString { get; set; }    
    //Insert Action for inserting the csv data into Fund_Management object
    @RemoteAction
    public static void insertAccounts(List<Fund_Management__c> fundlist){                 
        try{
            //Schema.DescribeFieldResult fId = Fund_Management__c.fnameMonthYear__c.getDescribe();
            //Schema.sObjectField T = fId.getSObjectField();
            Schema.SObjectField fId = Fund_Management__c.Fields.fnameMonthYear__c;
            //upsert(fundlist,fId,false);
            //insert fundlist;            
            //Database.Upsert(fundlist,fId,false);
              upsert fundlist fnameMonthYear__c;                      
            }catch(DmlException e) {
                System.debug('An unexpected error has occurred: ' + e.getMessage());
            }
       }
    
    public List<List<String>> getResults() {        
       List<List<String>> parsedCSV = new List<List<String>>();
       rowCount = 0;
       colCount = 0;
       if (uploadFile!= null){
            fileString = uploadFile.toString();       
            parsedCSV = parseCSV(fileString, false);
            rowCount = parsedCSV.size();
            for (List<String> row : parsedCSV){
               if (row.size() > colCount){
               colCount = row.size();
               }
            }
       }
       System.debug('nameFile' + nameFile);
       return parsedCSV;
     }
     public static List<List<String>> parseCSV(String contents,Boolean skipHeaders) {
         List<List<String>> allFields = new List<List<String>>();
         // replace instances where a double quote begins a field containing a comma
         // in this case you get a double quote followed by a doubled double quote
         // do this for beginning and end of a field
         contents = contents.replaceAll(',"""',',"DBLQT').replaceall('""",','DBLQT",');
         // now replace all remaining double quotes - we do this so that we can reconstruct
         // fields with commas inside assuming they begin and end with a double quote
         contents = contents.replaceAll('""','');
         // we are not attempting to handle fields with a newline inside of them
         // so, split on newline to get the spreadsheet rows
         List<String> lines = new List<String>();
         try {
         lines = contents.split('\r'); // using carriage return accomodates windows, unix, and mac files
         }
         catch (System.ListException e) {
         System.debug('Limits exceeded?' + e.getMessage());
         }
         Integer num = 0;
         for(String line: lines){
             // check for blank CSV lines (only commas)
             if (line.replaceAll(',','"').trim().length() == 0) break;
                 List<String> fields = line.split(',');
                 List<String> cleanFields = new List<String>();
                 System.debug('fields' + fields );
                 String compositeField;
                 Boolean makeCompositeField = false;
     
                 for(String field: fields) {
                     if (field.startsWith('"') && field.endsWith('"')) {
                     cleanFields.add(field.replaceAll('DBLQT',''));
                     }
                     else if (field.startsWith('"')) {
                     makeCompositeField = true;
                     compositeField = field;
                     }
                     else if (field.endsWith('"')) {
                     compositeField += ',' + field;
                     cleanFields.add(compositeField.replaceAll('DBLQT',''));
                     makeCompositeField = false;
                     }
                     else if (makeCompositeField){
                     compositeField +=  ',' + field;
                     }
                     else {
                     cleanFields.add(field.replaceAll('',''));
                     }
                }
                allFields.add(cleanFields);
            }
        //if (skipHeaders) allFields.remove(0);
        return allFields;     
     }
    public void checkblankfile(){
        if(rowCount == 0) {
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'The file is empty.'));
        }        
     }
    public PageReference vfReciredt(){         
        if(uploadFile ==null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please Upload File'));
        }
        else{
            //PageReference redirect = new PageReference('/apex/Fund_List?sfdc.tabName=01r900000007xyR');
            //redirect.setRedirect(true);
            //return redirect;
        }
        return null;
    }

}

 

 highlighted area is not get covered anybody knows to get code coverage for that area..... and also let me know how to increase code coverage for code included in conditional statements like  for, if, else conditions

 

and here is mine Test class

 

@isTest
private class csvControllerTest
{    
   static testMethod void myUnitTest() {
        
        //Test converage for the cumulativePerformanceChart visualforce page        
        PageReference pageRef = Page.ImportCSV;
        Test.setCurrentPageReference(pageRef);          
        // Perform our data preparation.
        //Insert Single Record
        Fund_Management__c fmssr = new Fund_Management__c(Fund_Name__c='test fund',Growth__c=1.2,Month__c='Jan',Year__c=2008);
        insert fmssr;
        //Insert Bulk Record
        List<Fund_Management__c> fmsbr = new List<Fund_Management__c>{};
                 
        for(Integer i = 0; i < 200; i++){
            Fund_Management__c f = new Fund_Management__c(Fund_Name__c = 'Test Fund '+i,Growth__c = 1.2,Month__c = 'Jan',Year__c = 2008);
            fmsbr.add(f);
        }        
         //Now insert data causing an contact trigger to fire.
        Test.startTest();
        try {
             insert fmsbr;        
        }catch(DmlException e) {
           
            }       
        Test.stopTest();       
        // Query the database for the newly inserted records.
        List<Fund_Management__c> insertedFunds = [SELECT Fund_Name__c, Growth__c ,Month__c,Year__c FROM Fund_Management__c];             
        // Assert that the Description fields contains the proper value now.
        for(Fund_Management__c a : insertedFunds){
        System.assert(insertedFunds != null);
        }        
    
        String csvContent = 'Test,Jan,2001,3,l\nTest1,Feb,2001,4,k';
        //initialization of csvcontroller
        CSVcontroller csv = new CSVcontroller();
        List<List<String>> parsedCSV = CSVcontroller.parseCSV(csvContent,false);
        system.assertEquals(parsedCSV[0][0],'Test');
        system.assertEquals('Jan',parsedCSV[0][1]);
        system.assertEquals('2001',parsedCSV[0][2]);
        system.assertEquals('3',parsedCSV[0][3]);
        //Call All Methods In CsvController
         csv.getResults();
         csv.vfReciredt();
         csv.checkblankfile();           
         CSVcontroller.insertAccounts(fmsbr);
    }
}

 

in that i have write the insert logic for 1 records and insert logic for 200 records still not getting 100 % code coverage

Hi I'm trying to write test cases using isTest annotation

first of all i have initialized my visualforce page.

than initialized the controller

and iam calling each methods in controller

 

but in my code coverage is only 85% only....... i know 75% code coverage is enough for deploy code in production organization but iam expecting 100% code coverage here is my code please let me any suggesions

 

Here is mine Controller

 

   public class MyQueryController{

   public Set<String>myQueryResults { get; Public set; }  

   public List<Fund_Management__c> getUniquedata(){

   myQueryResults= new Set<String>();  

    List<Fund_Management__c> query=[SELECT Fund_Name__c FROM Fund_Management__c];

    System.debug('Results'+query);  9    for(Fund_Management__c results : query){  

    myQueryResults.add(results.Fund_Name__c); 

   }  

    return query;

    }  

  }

 

highlighted area is not get covered anybody knows to get code coverage for that area..... and also let me know how to increase code coverage for code included in conditional statements like  for, if, else conditions

 

 

 

And here is mine test class

 

@isTest
Private class MyQueryControllerTest{
    Static testmethod void UnitTest(){
    Set<String> myQueryResults = new Set<String>{};
    List<Fund_Management__c> query=[SELECT Fund_Name__c FROM Fund_Management__c];
    //initialized the vf page here
    PageReference pageref = Page.MyQueryPage;
    Test.setCurrentPageReference(pageref);
    //initialized the controller
    MyQueryController myqc = new MyQueryController();
    //calling methods in controller
    myqc.getUniquedata();
    }
}

 

I am trying to Run Schedule job........but Schedulable class has jobs pending or in progress? This Error is occurs again and again, i have deleted the scheduler class and tried again still same problem occurs if have any suggetions please let me know...... here is my scheduler class for send Emails to employee on his birth day :-

 

global class BirthdayMailSend implements Schedulable
{
    global void execute (SchedulableContext ctx)
    {
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
    for ( Employee__c emp : [SELECT Id, Name,email__c,First_Name__c FROM Employee__c WHERE Birth_date__c = TODAY] )
    {
     mail.setSubject('New Employee Record Created..!');
     mail.setHtmlBody('Hello'+emp.First_Name__c+'!<br/>today is your birth day bhikarya cake kap nahi tar muskadin');
     mail.setToAddresses(new String[] {emp.email__c});
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });        
    }
    BirthdayMailSend mc = new BirthdayMailSend();
    String sch = '0 0,1 * * * *';
    system.schedule('Birthdaymail', sch, mc);
    }
}

We have Javascript Remoting in use in our Production instance (Summer '11) and it works like a charm. Our Sandbox was just "upgraded" to Winter 12 and now we are getting reference errors on code that has not changed in 2 months. What gives?

I keep getting this error when I try to validate a deployment. The classes in question are not schedule classes or related to scheduling in any way. Once is a controller for a VF page, then tests for that controller, and a utility class with some static methods.

I have a completely seperate and unrelated scheduled job but it was not running when I got this error.

 

 

BUILD FAILED
C:\Documents and Settings\venable\Desktop\deploy\build.xml:7: Failures:
classes/configAddProductsVF.cls(1,8):Schedulable class has jobs pending or in progress
classes/configAddProductsVFTEST.cls(1,8):Schedulable class has jobs pending or in progress
classes/utility.cls(1,8):Schedulable class has jobs pending or in progress

Anyone seen this before?

Thanks,
Jason

  • December 22, 2009
  • Like
  • 0