You need to sign in to do that
Don't have an account?
admin 7
Can any one help in Test class please
This is my code please write test class for my class
Apex Code:
public with sharing class ContactNew{
public contact org { get; private set; }
private ApexPages.StandardController sController;
private String queryString;
public ContactNew(ApexPages.StandardController controller) {
sController = controller;
org = (contact)controller.getRecord();
}
public Pagereference SaveAndnew()
{
upsert org;
string s = '/' + ('' + org.get('Id')).subString(0, 3) + '/e?';
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
return new Pagereference(s);
}
}
Visualforce Page
<apex:page standardController="contact" extensions="ContactNew" >
<apex:sectionHeader Title="Contact edit" Subtitle="New contact"/>
<apex:form >
<apex:pageBlock Title="contact Edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Save & New" action="{!SaveAndnew}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
<apex:pageBlockSection >
<apex:inputField value="{!Contact.FirstName}"/>
<apex:inputField value="{!Contact.LastName}"/>
</apex:pageBlockSection>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
public with sharing class ContactNew{
public contact org { get; private set; }
private ApexPages.StandardController sController;
private String queryString;
public ContactNew(ApexPages.StandardController controller) {
sController = controller;
org = (contact)controller.getRecord();
}
public Pagereference SaveAndnew()
{
upsert org;
string s = '/' + ('' + org.get('Id')).subString(0, 3) + '/e?';
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
return new Pagereference(s);
}
}
Visualforce Page
<apex:page standardController="contact" extensions="ContactNew" >
<apex:sectionHeader Title="Contact edit" Subtitle="New contact"/>
<apex:form >
<apex:pageBlock Title="contact Edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Save & New" action="{!SaveAndnew}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
<apex:pageBlockSection >
<apex:inputField value="{!Contact.FirstName}"/>
<apex:inputField value="{!Contact.LastName}"/>
</apex:pageBlockSection>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Please find below Test Class for your class which has 100% code coverage.
Also find below few links for Test Classes:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Please let me know if that helps you.
Best Regards,
BALAJI
All Answers
Please find below Test Class for your class which has 100% code coverage.
Also find below few links for Test Classes:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Please let me know if that helps you.
Best Regards,
BALAJI
Thanks for your valuable answer