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
Shahab KhanShahab Khan 

I unable to deploy my changes from sandbox to production

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 MemberDonor {
   
   Account account;
   Contact contact;

   public MemberDonor() {
       account = new Account();
   }
   
   public Contact getContact() {
      if(contact == null) contact = new Contact();
      return contact;
   }

   public String StrSaveResult { get; set; }
   
   public PageReference save() {
      
      try {
          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 {
                 account.name = contact.FirstName + ' ' + contact.LastName;
                 account.phone = contact.phone;
                  
                 insert account;
                  
                 contact.accountId = account.id;
                 insert contact;
           
                 StrSaveResult = 'Your membership created successfully!';
          }
      } catch (Exception ex) {
           StrSaveResult = ex.getMessage(); 
      }
      contact = null;
      return null;
   }

}

and here is may visual force page code
<apex:page controller="MemberDonor" showheader="false" sidebar="false" standardStylesheets="false" cache="false" >
    <apex:stylesheet value="/volunteers/servlet/servlet.FileDownload?file=015F0000002hVFR" />
    <apex:form styleClass="cssForm" >       
        <table columns="4" >
            <tr>
                <td  colspan="4" ><b>Member Information:</b></td>
            </tr>
            <!-- first we specify the fields we require for Contact matching -->
            <tr>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.FirstName.Label}" for="txtFirstName" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.FirstName}" id="txtFirstName" required="true" styleClass="cssInputFields" /></td>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.MI__c.Label}" for="txtMI" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.MI__c}" id="txtMI" styleClass="cssInputFields" /></td>
            </tr>
            <tr>    
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.LastName.Label}" for="txtLastName" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.LastName}" id="txtLastName" required="true" styleClass="cssInputFields" /></td>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.Spouse_First_Name__c.Label}" for="txtSpouse_First_Name" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.Spouse_First_Name__c}" id="txtSpouse_First_Name" styleClass="cssInputFields" /></td>
            </tr>
            <tr>    
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.Spouse_MI__c.Label}" for="txtSpouse_MI" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.Spouse_MI__c}" id="txtSpouse_MI" styleClass="cssInputFields" /></td>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.Spouse_Last_Name__c.Label}" for="txtSpouse_Last_Name" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.Spouse_Last_Name__c}" id="txtSpouse_Last_Name" styleClass="cssInputFields" /></td>
            </tr>
            <tr>    
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.MailingStreet.Label}" for="txtMailingStreet" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.MailingStreet}" id="txtMailingStreet" styleClass="cssInputFields" /></td>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.MailingCity.Label}" for="txtMailingCity" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.MailingCity}" id="txtMailingCity" styleClass="cssInputFields" /></td>
            </tr>
            <tr>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.MailingState.Label}" for="txtMailingState" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.MailingState}" id="txtMailingState" styleClass="cssInputFields" /></td>    
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.MailingPostalCode.Label}" for="txtMailingPostalCode" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.MailingPostalCode}" id="txtMailingPostalCode" styleClass="cssInputFields" /></td>
            </tr>
            <tr>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.MailingCountry.Label}" for="txtMailingCountry" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.MailingCountry}" id="txtMailingCountry" styleClass="cssInputFields" /></td>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.Email.Label}" for="txtEmail" /></td>
                <td class="cssInputFieldsColumn" ><apex:inputField value="{!contact.Email}" id="txtEmail" required="true" styleClass="cssInputFields" /></td>
            </tr>
            <tr>
                <td class="cssLabelsColumn" ><apex:outputLabel value="{!$ObjectType.Contact.Fields.Phone.Label}" for="txtPhone" /></td>
                <td class="cssInputFieldsColumn" colspan="3" ><apex:inputField value="{!contact.Phone}" id="txtPhone" styleClass="cssInputFields" /></td>
            </tr>
            <tr>
                <td colspan="4" ><b>Membership Information:</b></td>
            </tr>
            <tr>
                <td class="cssInputFieldsColumn" colspan="4" >
                    <apex:selectRadio value="{!contact.New_Or_Renew__c}" >
                        <apex:selectOption itemValue="New Membership" itemLabel="New Membership?"/>
                        <apex:selectOption itemValue="Renew Membership" itemLabel="Renew Membership"/>
                    </apex:selectRadio>
                </td>
            </tr>
            <tr>
                <td ><apex:outputLabel value="Select Membership:" /></td>
                <td class="cssInputFieldsColumn" colspan="3" >
                    <apex:selectRadio value="{!contact.Select_Membership__c}" >
                        <apex:selectOption itemValue="Yearly Membership Individual $60 Per Year" itemLabel="Yearly Indiviual $60"/>
                        <apex:selectOption itemValue="Yearly Membership Husband and Wife $100 Per Year" itemLabel="Yearly Husband and Wife $100 per year"/>
                        <apex:selectOption itemValue="Life Time Membership Individual $1000" itemLabel="Life Time Indiviual $1000"/>
                    </apex:selectRadio>
                </td>
            </tr>
            <tr>
                <td colspan="4" ><b>I want to donate tax deductable donation to ADAMS Center.</b></td>
            </tr>
            <tr>
                <td ><apex:outputLabel value="Donation Frequency:" /></td>
                <td class="cssInputFieldsColumn" colspan="3" >
                    <apex:selectRadio >
                        <apex:selectOption itemValue="0" itemLabel="Single Donation"/>
                        <apex:selectOption itemValue="1" itemLabel="Recurring Donation"/>
                    </apex:selectRadio>
                </td>
            </tr>
            <tr>
                <td></td>        
                <td class="cssInputFieldsColumn" colspan="3" ><apex:commandButton value="Save" action="{!save}" /></td>
            </tr>
            <tr>
                <td></td>
                <td class="cssInputFieldsColumn" colspan="3" ><apex:outputLabel value="{!StrSaveResult}" /></td>
            </tr>   
        </table>
    </apex:form>
</apex:page>

Can anybody help me how can i improve it so that it deployes to the production successfuly.
Thanks in advance.
Best Answer chosen by Shahab Khan
Ramesh KallooriRamesh Kalloori
Please find the below test class for MemberDonor.

@isTest(SeeAllData = true) 
private class MemberDonor_TC{
@isTest static void testCallout() {
    MemberDonor MD=new MemberDonor();
    MD.getContact();
    MD.save();
}
}

and the org test coverage<75% then also the class will not move to production.

thanks,
RAmesh