+ Start a Discussion
Shahab KhanShahab Khan 

unable to deploy my changes from sandbox to production Even have test class

Hi,

I have created a custom controler and visual force page in sandbox its working fine in sandbox now i want to deploy it to production.
Bit it fails due to test coverage percentage as shown below.
User-added image
Here is my custom controller class
public class Donor {
   
    Account account;
    Contact contact;
    //Opportunity opportunity;
    //OpportunityContactRole role;
    //npe03__Recurring_Donation__c recDonation;
    //BluePay_DNA__Rebilling_Cycle__c rebilling_cycle;
    //BluePay_DNA__Payment__c bluePayment;
    public String payment_type {get;set;}
    public String current_date {get;set;}
    
    
    public Donor() {
       account = new Account();
       //opportunity = new Opportunity();
       //role = new OpportunityContactRole();
       //recDonation = new npe03__Recurring_Donation__c();
       //bluePayment = new BluePay_DNA__Payment__c();
       //rebilling_cycle = new BluePay_DNA__Rebilling_Cycle__c();
       payment_type = 'Credit Card';
       Datetime cDT = System.now();
       current_date = cDT.format('MM/d/yyyy');
    }
   
   public Contact getContact() {
      if(contact == null) contact = new Contact();
      return contact;
   }

   public String StrSaveResult { get; set; }
   
   public PageReference save() {
      
      list<Contact> listCon = [select Id from Contact where Lastname=:contact.LastName and Firstname=:contact.FirstName and Email=:contact.Email];
      if (listCon.size() > 0) {
            StrSaveResult = 'Sorry the information you provided has already registered!';
      }
      else {
             
             try
             { 
                 // First create account
                 account.name = contact.FirstName + ' ' + contact.LastName;
                 account.phone = contact.phone;
                  
                 insert account;
                 
                 // Then create contact 
                 contact.accountId = account.id;
                 contact.RecordTypeId = '012F00000013Gk2';
                 insert contact;
                 
                 // Enable gateway account
                 
                 //String account_id = '100181797727';
                 
                 if(contact.Donation_Type__c != null && (contact.Donation_Type__c == 'ADAMS 10/10 Club' || contact.Donation_Type__c == 'ADAMS Operations' || contact.Donation_Type__c == 'Other'))
                 {
                    //Adams Operations
                    //9EOFRZWUHAFHOFMXWHHYWMGLT/Y5.GBT
                    //account_id = '100181797727';
                 }
                 else
                 if(contact.Donation_Type__c != null && contact.Donation_Type__c == 'Ashburn New Masjid')
                 {
                    //Ashburn Acquisition
                    //CF7GXZN46AU8RMQQ7VCKQF89V5XNIFEO
                    //account_id = '100181719805';
                 }
                 else
                 if(contact.Donation_Type__c != null && contact.Donation_Type__c == 'Ashburn Operations')
                 {
                    //Ashburn
                    //QNLXPZ3/JSFU8ERRARDW6LBOMWCVMDG5
                    //account_id = '100181704859';
                 }
                 else
                 if(contact.Donation_Type__c != null && contact.Donation_Type__c == 'Gainesville New Masjid')
                 {
                    //Gainesville New Masjid
                    //NS2ULFHQ2GDUYEE9VAWUAUWWEW3YRCJU
                    //account_id = '100181686984';
                 }
                 else
                 if(contact.Donation_Type__c != null && contact.Donation_Type__c == 'Gainesville Operations')
                 {
                    //Gainesville Operations
                    //PCPK2DOIVSLQR9ZT78HINNBLOVQA8KPN
                    //account_id = '100181796062';
                 }
                 else
                 if(contact.Donation_Type__c != null && contact.Donation_Type__c == 'Phase III Construction')
                 {
                    //PhaseThree
                    //OBDNHVA7KCMALRUII7OK8ZMSCQPBPSG8
                    //account_id = '100181703930';
                 }
                 else
                 if(contact.Donation_Type__c != null && contact.Donation_Type__c == 'Sully Center')
                 {
                    //Sully Ops
                    //VGX6MUHHFACV4PDTTP2KM721NSXE72ML
                    //account_id = '100181718020';
                 }
                 else
                 if(contact.Donation_Type__c != null && (contact.Donation_Type__c == 'Sadaqa' || contact.Donation_Type__c == 'Zakat' || contact.Donation_Type__c == 'Zakat Ul Fitr'))
                 {
                    //Zakat
                    //0PG850Z/HD.14VMN1SONYWUDPCAAOW.R
                    //account_id = '100181718495';
                 }
                 
                 //BluePay_DNA__BluePay_Gateway_Settings__c accountToUpdate;
//                 accountToUpdate = [SELECT BluePay_DNA__Enabled__c FROM BluePay_DNA__BluePay_Gateway_Settings__c WHERE BluePay_DNA__Enabled__c =True LIMIT 1];
//                 accountToUpdate.BluePay_DNA__Enabled__c = False;
//                 update accountToUpdate;
                 
                 //accountToUpdate = null;
//                 accountToUpdate = [SELECT BluePay_DNA__Enabled__c FROM BluePay_DNA__BluePay_Gateway_Settings__c WHERE BluePay_DNA__Account_ID__c =:account_id LIMIT 1];
//                 accountToUpdate.BluePay_DNA__Enabled__c = True;
//                 update accountToUpdate;
                 
                 // Add Donation
                 
                 if(contact.Donation_Frequeny__c != null && contact.Donation_Frequeny__c == 'Single')
                 {
                     //opportunity = null;
                     //role = null;
                     //bluePayment = null;
                     //opportunity = new Opportunity();
                     //role = new OpportunityContactRole();
                     //bluePayment = new BluePay_DNA__Payment__c();
                     
                     //opportunity.accountId = account.id;
//                     opportunity.name = account.name + ' Donation ' + current_date;
                     if(contact.Donataion_Amount__c != null && contact.Donataion_Amount__c != '')
                     {
                        //opportunity.amount = Integer.valueof(contact.Donataion_Amount__c);
                     }
                     else
                     {
                        //opportunity.amount = contact.DonataionAmountOther__c;
                     }
                     //opportunity.CloseDate = Date.today();
//                     opportunity.stageName = 'Posted';
//                     insert opportunity;
                     
                     // Then create opportunity role
                     //role.opportunityId = opportunity.id;
//                     role.contactId = contact.id;
//                     role.Role = '10';
//                     insert role;
                     
                     // Add Blue Pay Payment
                 
                     //bluePayment.BluePay_DNA__Account_Name__c = account.id;
//                     bluePayment.BluePay_DNA__Contact_Name__c = contact.id;
//                     bluePayment.BluePay_DNA__Opportunity_Name__c = opportunity.id;
//                     bluePayment.BluePay_DNA__Address__c = contact.MailingStreet;
//                     bluePayment.BluePay_DNA__City__c = contact.MailingCity;
//                     bluePayment.BluePay_DNA__State__c = contact.MailingState;
//                     bluePayment.BluePay_DNA__Zipcode__c = contact.MailingPostalCode;
//                     bluePayment.BluePay_DNA__Email__c = contact.Email;
//                     bluePayment.BluePay_DNA__Phone__c = contact.Phone;
//                     bluePayment.BluePay_DNA__Comments__c = contact.Member_Comments__c;
                     
                     if(contact.Donataion_Amount__c != null && contact.Donataion_Amount__c != '')
                     {
                        //bluePayment.BluePay_DNA__Amount__c = (Integer.valueof(contact.Donataion_Amount__c) - 1);
                     }
                     else
                     {
                        //bluePayment.BluePay_DNA__Amount__c = contact.DonataionAmountOther__c;
                     }
                     
                     //bluePayment.BluePay_DNA__Transaction_Type__c = 'Sale';
//                     bluePayment.BluePay_DNA__Is_External__c = 'Yes';
//                     bluePayment.BluePay_DNA__Is_Recurring__c = 'No';
                     
                     //bluePayment.BluePay_DNA__Payment_Type__c = payment_type;
                     
                     if(payment_type != null && payment_type == 'Credit Card')
                     {
                        //bluePayment.BluePay_DNA__Card_Number__c = contact.Card_Number__c;
//                        bluePayment.BluePay_DNA__Expiration_Month__c = contact.Expiration_Month__c;
//                        bluePayment.BluePay_DNA__Expiration_Year__c = contact.Expiration_Year__c;
//                        bluePayment.BluePay_DNA__CVV2__c = contact.CVV2__c;
                     }
                     else
                     {
                        //bluePayment.BluePay_DNA__Account_Type__c = contact.Account_Type__c;
//                        bluePayment.BluePay_DNA__Account_Number__c = contact.Account_Number__c;
//                        bluePayment.BluePay_DNA__Routing_Number__c = contact.Routing_Number__c;
                     }
                     //insert bluePayment;
                     
                 }
                 else if(contact.Donation_Frequeny__c != null &&  contact.Donation_Frequeny__c == 'Recurring')
                 {
                    //recDonation.Name = account.name + ' Recurring Donation ' + current_date;
                    if(contact.Donataion_Amount__c != null && contact.Donataion_Amount__c != '')
                     {
                        //recDonation.npe03__Amount__c = Integer.valueof(contact.Donataion_Amount__c);
                     }
                     else
                     {
                        //recDonation.npe03__Amount__c = contact.DonataionAmountOther__c;
                     }
                     //recDonation.npe03__Date_Established__c = Date.today();
//                     recDonation.npe03__Installment_Period__c = contact.Recurring_Period__c;
//                     recDonation.npe03__Contact__c = contact.id;
//                     insert recDonation;
                     
                     // Add Rebilling Cycle
                     
                     //rebilling_cycle = null;
//                     rebilling_cycle = new BluePay_DNA__Rebilling_Cycle__c();
                     
                     //rebilling_cycle.BluePay_DNA__Contact_Name__c = contact.id;
                     if(contact.Donataion_Amount__c != null && contact.Donataion_Amount__c != '')
                     {
                        //rebilling_cycle.BluePay_DNA__Rebill_Amount__c = Integer.valueof(contact.Donataion_Amount__c);
                     }
                     else
                     {
                        //rebilling_cycle.BluePay_DNA__Rebill_Amount__c = contact.DonataionAmountOther__c;
                     }
                     //rebilling_cycle.BluePay_DNA__Rebill_Cycles_Remaining__c = '12';
                     
                     if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Weekly')
                     {
                        //rebilling_cycle.Name = account.name + ' - ' + rebilling_cycle.BluePay_DNA__Rebill_Amount__c + ' - 1Week(s) cycle';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency_Number__c = '1';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency__c = 'Week(s)';   
                     }
                     else
                     if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Bi-Weekly')
                     {
                        //rebilling_cycle.Name = account.name + ' - ' + rebilling_cycle.BluePay_DNA__Rebill_Amount__c + ' - 2Week(s) cycle';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency_Number__c = '2';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency__c = 'Week(s)';   
                     }
                     else
                     if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Monthly')
                     {
                        //rebilling_cycle.Name = account.name + ' - ' + rebilling_cycle.BluePay_DNA__Rebill_Amount__c + ' - 1Month(s) cycle';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency_Number__c = '1';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency__c = 'Month(s)';  
                     }
                     else
                     if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Annually')
                     {
                        //rebilling_cycle.Name = account.name + ' - ' + rebilling_cycle.BluePay_DNA__Rebill_Amount__c + ' - 1Year(s) cycle';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency_Number__c = '1';
//                        rebilling_cycle.BluePay_DNA__Rebill_Frequency__c = 'Year(s)';   
                     }
                     
                     //rebilling_cycle.BluePay_DNA__Rebill_Next_Date__c = System.now();
//                     rebilling_cycle.BluePay_DNA__Is_External__c = 'Yes';
//                     rebilling_cycle.BluePay_DNA__Payment_Type__c = payment_type;
                     
                     if(payment_type != null && payment_type == 'Credit Card')
                     {
                        //rebilling_cycle.BluePay_DNA__Card_Number__c = contact.Card_Number__c;
//                        rebilling_cycle.BluePay_DNA__Expiration_Month__c = contact.Expiration_Month__c;
//                        rebilling_cycle.BluePay_DNA__Expiration_Year__c = contact.Expiration_Year__c;
                     }
                     else
                     {
                        //rebilling_cycle.BluePay_DNA__Payment_Type__c = 'Check';
//                        rebilling_cycle.BluePay_DNA__Account_Type__c = contact.Account_Type__c;
//                        rebilling_cycle.BluePay_DNA__Account_Number__c = contact.Account_Number__c;
//                        rebilling_cycle.BluePay_DNA__Routing_Number__c = contact.Routing_Number__c;
                     }
                     //insert rebilling_cycle;
                     
                     Date re_today_date = Date.today();
                     
                     // Add Recurring Donations under Oppertunity
                     
                     for (Integer i = 1; i <= 12; i++)
                     {
                         //opportunity = null;
//                         role = null;
//                         opportunity = new Opportunity();
//                         role = new OpportunityContactRole();
                         
                         //opportunity.accountId = account.id;
//                         opportunity.npe03__Recurring_Donation__c = recDonation.id;
//                         opportunity.name = account.name + ' Donation (' + i + ' of 5) ' + current_date;
                         if(contact.Donataion_Amount__c != null && contact.Donataion_Amount__c != '')
                         {
                            //opportunity.amount = Integer.valueof(contact.Donataion_Amount__c);
                         }
                         else
                         {
                            //opportunity.amount = contact.DonataionAmountOther__c;
                         }
                        
                         if(i == 1)
                         {
                            //opportunity.CloseDate = re_today_date;
                         }
                         else
                         {
                            if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Weekly')
                             {
                                re_today_date = re_today_date.addDays(7);
                                //opportunity.CloseDate = re_today_date;
                             }
                             else if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Bi-Weekly')
                             {
                                re_today_date = re_today_date.addDays(14);
                                //opportunity.CloseDate = re_today_date;
                             }
                             else if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Monthly')
                             {
                                re_today_date = re_today_date.addMonths(1);
                                //opportunity.CloseDate = re_today_date;
                             }
                             else if(contact.Recurring_Period__c != null &&  contact.Recurring_Period__c == 'Yearly')
                             {
                                re_today_date = re_today_date.addYears(1);
                                //opportunity.CloseDate = re_today_date;
                             }
                         }
                         
                         
                         //opportunity.stageName = 'Pledged';
//                         insert opportunity;
                         
                         // Then create opportunity role
                         //role.opportunityId = opportunity.id;
//                         role.contactId = contact.id;
//                         role.Role = '10';
//                         insert role;
                     }
                 }
                 
                 //account_id = '100181797727';
                 //accountToUpdate = null;
//                 accountToUpdate = [SELECT BluePay_DNA__Enabled__c FROM BluePay_DNA__BluePay_Gateway_Settings__c WHERE BluePay_DNA__Account_ID__c =:account_id LIMIT 1];
//                 accountToUpdate.BluePay_DNA__Enabled__c = True;
//                 update accountToUpdate;
           
                 StrSaveResult = 'Your donnor account created successfully. Thank you for your donation.';
             }
             catch (exception ex)
             {
                Delete account;
                StrSaveResult = 'Exception type caught: ' + ex.getTypeName();
                StrSaveResult += '<br>Message: ' + ex.getMessage();
                StrSaveResult += '<br>Cause: ' + ex.getCause();
                StrSaveResult += '<br>Line number: ' + ex.getLineNumber();
                StrSaveResult += '<br>Stack trace: ' + ex.getStackTraceString();
             }
      }
      contact = null;
      return null;
   }

}

and here is may visual force page 
User-added image
And here is my test class
@isTest(SeeAllData = true)

private class Donor_TC
{

    @isTest static void testCallout() {
    
        Donor MD = new Donor();
        Contact contact = MD.getContact();
        contact.FirstName = 'Humma';
        contact.Middle_Name__c = 'Irfan';
        contact.LastName = 'Khan';
        contact.Email = 'huma.irfan@purelogics.net';
        contact.Phone = '923236161853';
        MD.save();
    }

}



Can anybody help me how can i improve it so that it deployes to the production successfuly.
Thanks in advance.
kibitzerkibitzer
Two possibilities come to mind.

In your error message, you have 69% test coverage.

The first thing I would test is - what is the test coverage on production before you install this changeset?  When you do an install, it looks at the overall test coverage, not just the test coverage on the class you are adding. You may need to fix some existing code to bring up the overall test coverage.

Second, is it possible that a record with this first name, last name and Email already exists on the org?  If so, your test code will abort early because you have seealldata set to true. Based on a quick read of the code, you should be able to easily use it with seealldata =false, which would resolve that issue (unless you have other trigger code on the org that doesn't fail gracefully when there is no data - which is common on many orgs and should be addressed when you have the chance).