-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
1Questions
-
3Replies
Help with test class controller extension
Hi,
I'm pretty new to Apex development.
Upon request I was able to create a simple apex class which based on some logic, saves and clones a contact to a new Account. A Visual force page complets the set.
Here's the VF page :
<apex:page standardController="Contact" showHeader="true" tabStyle="contact" extensions="Contactedit"> <chatter:feedWithFollowers entityId="{!contact.id}"/> <apex:sectionHeader title="Contact" subtitle="{!Contact.name}"/> <apex:form id="theForm"> <apex:pageBlock title="Edit Contact" id="thePageBlock" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Contact Information" columns="2" collapsible="True"> <apex:inputField value="{!Contact.Salutation}"/> <apex:inputField value="{!Contact.Phone}"/> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField value="{!Contact.Fax}"/> <apex:inputField value="{!Contact.LastName}"/> <apex:inputField value="{!Contact.MobilePhone}"/> <apex:inputField value="{!Contact.AccountId}"/> <apex:inputField value="{!Contact.Email}"/> <apex:inputField value="{!Contact.Title}"/> <apex:inputField value="{!Contact.Email_2__c}"/> <apex:inputField value="{!Contact.Department}"/> <apex:inputField value="{!Contact.Email_Opt_Out_Date__c}"/> </apex:pageBlockSection> <apex:pageBlockSection id="Description" title="Description" columns="1" collapsible="True"> <apex:inputTextArea id="newDesc" value="{!Contact.Description}"/> </apex:pageBlockSection> <!-- apex:pageBlockSection title="Contact Photo" columns="1"> <apex:inputField value="{!Contact.Foto__c}"/> </apex:pageBlockSection !--> <apex:pageBlockSection id="Profile" title="Contact Profile" columns="2" collapsible="True"> <apex:inputField value="{!Contact.CMF_Profile__c}"/> <apex:inputField value="{!Contact.BV_Profile__c}"/> <apex:inputField value="{!Contact.MMF_Profile__c}"/> <apex:inputField value="{!Contact.Swapswire_Profile__c}"/> <apex:inputField value="{!Contact.Trade_Cancellation_CMF__c}"/> <apex:inputField value="{!Contact.BV_Approval__c}"/> <apex:inputField value="{!Contact.BV_Fees__c}"/> <apex:inputField value="{!Contact.Accounting__c}"/> <apex:inputField value="{!Contact.MTS_Data__c}"/> <apex:inputField value="{!Contact.DataFeed_UserName__c}"/> <apex:inputField value="{!Contact.AssistantName}"/> <apex:inputField value="{!Contact.AssistantPhone}"/> <apex:inputField value="{!Contact.Inactive_Contact__c}"/> <apex:pageBlockSectionItem > <apex:actionRegion > <B><apex:outputLabel value="Left the Company"/></B> <apex:outputPanel > <apex:inputCheckbox value="{!Contact.Left_the_Company_Flag__c}"> <apex:actionSupport event="onclick" rerender="Profile" status="status"/> </apex:inputCheckbox> <apex:actionStatus startText="applying value..." id="status"/> </apex:outputPanel> </apex:actionRegion> </apex:pageBlockSectionItem> <apex:pageBlockSection Title="Left the Company" columns="2" rendered="{!Contact.Left_the_Company_Flag__c}"> <apex:inputField value="{!Contact.Moved_to__c}"/> <apex:inputField value="{!Contact.Clone_to_new_Account_without_Profile__c}"/> <apex:inputField value="{!Contact.Comment__c}"/> <apex:inputField value="{!Contact.Clone_to_new_Account_with_Profile__c}"/> </apex:pageBlockSection> </apex:pageBlockSection> <apex:pageBlockSection id="Address2" title="Address" columns="2"> <apex:inputField value="{!Contact.MailingStreet}"/> <apex:inputField value="{!Contact.MailingCity}"/> <apex:inputField value="{!Contact.MailingPostalCode}"/> <apex:inputField value="{!Contact.MailingState}"/> <apex:inputField value="{!Contact.MailingCountry}"/> </apex:pageBlockSection> <apex:pageblocksection id="MTS" Title="MTS Market Configuration" Columns="2"> <apex:inputField value="{!Contact.Linked_Membercodes__c}"/> <apex:inputField value="{!Contact.MTS_CertificateType__c}"/> <apex:pageblocksection id="CMF" Title="CMF Platform" Columns="1"> <apex:inputField value="{!Contact.CMFI_UserID__c}"/> <apex:inputField value="{!Contact.CMFI_User_Profile__c}"/> <apex:inputField value="{!Contact.CMFI_Platform__c}"/> <apex:outputField value="{!Contact.CMF_Software_Signature__c}"/> <apex:outputField value="{!Contact.CMFI_Last_Login__c}"/> <apex:outputField value="{!Contact.Multimarket_SW_version__c}"/> <apex:outputField value="{!Contact.Network_Type__c}"/> </apex:pageblocksection> <apex:pageblocksection id="MMF" Title="MMF Platform" Columns="1"> <apex:inputField value="{!Contact.MMFI_UserID__c}"/> <apex:inputField value="{!Contact.MMFI_User_Profile__c}"/> <apex:inputField value="{!Contact.MMF_Swap_User_ID__c}"/> <apex:inputField value="{!Contact.Swapswire_Account__c}"/> <apex:inputField value="{!Contact.MMFI_Platform__c}"/> </apex:pageblocksection> </apex:pageblocksection> </apex:pageBlock> </apex:form> </apex:page>
and the class :
public class Contactedit { public Contact Contact {get;set;} private ApexPages.standardController controller {get;set;} Public boolean clonawo {get;set;} Public boolean clonawi {get;set;} // recovers from Accounts the billing details public Account accountmoved { get{ if (accountmoved == null) { accountmoved = [select BillingStreet,BillingCity,BillingCountry,BillingPostalCode,BillingState from account where id =: contact.moved_to__c]; } return accountmoved; } set; } public contact clonecontact { get{ //initialize the new contact if (clonecontact == null){ contact t = new contact(); //fill the fields of the new contact record t.firstname = contact.firstname; t.lastname = contact.lastname; t.salutation = contact.salutation; t.accountid = contact.moved_to__c; t.title = contact.Title; t.OwnerId =Userinfo.getUserId(); t.Left_the_Company_flag__c = false; t.MailingStreet = accountmoved.BillingStreet; t.MailingCity = accountmoved.BillingCity; t.MailingCountry = accountmoved.BillingCountry; t.MailingPostalCode = accountmoved.BillingPostalCode; t.MailingState = accountmoved.BillingState; t.Phone = '+00'; System.debug('clonawi = ' + clonawi); if ((contact.Clone_to_new_Account_with_Profile__c == true)|| (clonawi == true)) { t.accounting__c = contact.accounting__c; t.bv_approval__c = contact.bv_approval__c; t.bv_fees__c = contact.bv_fees__c; t.bv_Profile__c = contact.bv_Profile__c; t.CMF_Profile__c = contact.CMF_Profile__c; t.MMF_Profile__c = contact.MMF_Profile__c; t.Swapswire_Profile__c = contact.Swapswire_Profile__c; t.Trade_Cancellation_CMF__C = contact.Trade_Cancellation_CMF__C; } clonecontact = t; } return clonecontact; } set; } public Contactedit(ApexPages.StandardController stdController) { // constructor controller = stdController; this.contact= (contact)stdController.getRecord(); } public void createcontactAndclone(){ // check the ownerId of the position before creating the jobApp & task // the Task cannot be owned by a Queue // String ownerId = checkOwnerIdForQueue(SelectedPosition.OwnerId); // We update the current contact instead of insert try{ //insert contact; contact.Clone_to_new_Account_without_Profile__c = false; contact.Clone_to_new_Account_with_Profile__c = false; update contact; } catch (Exception e){ ApexPages.addMessages(e); } // checks if either clone was selected and of course the company where moved. //if ((contact.Moved_to__c != null) && ((contact.Clone_to_new_Account_without_Profile__c == true)||(contact.Clone_to_new_Account_with_Profile__c== true))) if ((contact.Moved_to__c != null) && ((clonawo == true)||(clonawi == true))) { try{ system.debug('#######' + clonecontact); // insert the new record on contact insert clonecontact; //catch exception } catch (Exception e){ ApexPages.addMessages(e); } } } public PageReference save(){ clonawo = contact.Clone_to_new_Account_without_Profile__c; clonawi = contact.Clone_to_new_Account_with_Profile__c; // updated the Contact and eventually create a new one. createcontactAndclone(); // use the standard controller to perform the save and redirect return controller.view(); } }
@isTest private class Test_Contactedit { public static testMethod void Contactedit_Test() { PageReference pageRef = Page.Contact_Edit_layout; Test.setCurrentPage(pageRef); Contactedit controller = new Contactedit(new ApexPages.StandardController()); String nextPage = controller.save().getUrl(); ApexPages.currentPage().getParameters().put('ContactId', [select id from contact limit 1].id); //extension = new contactedit(new ApexPages.StandardController(cont)); controller.Left_the_company_flag__c=true; controller.Moved_to__c='001R000000bn4Dg'; controller.Clone_to_new_Account_with_profile__c=true; nextPage = controller.save().getUrl(); } }
Save error: Constructor not defined: [ApexPages.StandardController].<Constructor>() Test_Contactedit.cls line 30 Force.com save problem
- elpaso750
- December 16, 2010
- Like
- 0
Visual force Table row components are not re-rendering after deleted one row, incorrect index
Hi All,
My Visual force table row inside the repeat tag, not re-endering its component name properly after delete one row. Suppose if the table has 3 rows and if delete the first row( menas row index 0), the name of the coponent remains as 1 and 2 instead of 0 and 1. Please help me those having faced this or knows regarding this issue,
Thanks.
- Hani M
- December 16, 2010
- Like
- 0
Help with test class controller extension
Hi,
I'm pretty new to Apex development.
Upon request I was able to create a simple apex class which based on some logic, saves and clones a contact to a new Account. A Visual force page complets the set.
Here's the VF page :
<apex:page standardController="Contact" showHeader="true" tabStyle="contact" extensions="Contactedit"> <chatter:feedWithFollowers entityId="{!contact.id}"/> <apex:sectionHeader title="Contact" subtitle="{!Contact.name}"/> <apex:form id="theForm"> <apex:pageBlock title="Edit Contact" id="thePageBlock" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Contact Information" columns="2" collapsible="True"> <apex:inputField value="{!Contact.Salutation}"/> <apex:inputField value="{!Contact.Phone}"/> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField value="{!Contact.Fax}"/> <apex:inputField value="{!Contact.LastName}"/> <apex:inputField value="{!Contact.MobilePhone}"/> <apex:inputField value="{!Contact.AccountId}"/> <apex:inputField value="{!Contact.Email}"/> <apex:inputField value="{!Contact.Title}"/> <apex:inputField value="{!Contact.Email_2__c}"/> <apex:inputField value="{!Contact.Department}"/> <apex:inputField value="{!Contact.Email_Opt_Out_Date__c}"/> </apex:pageBlockSection> <apex:pageBlockSection id="Description" title="Description" columns="1" collapsible="True"> <apex:inputTextArea id="newDesc" value="{!Contact.Description}"/> </apex:pageBlockSection> <!-- apex:pageBlockSection title="Contact Photo" columns="1"> <apex:inputField value="{!Contact.Foto__c}"/> </apex:pageBlockSection !--> <apex:pageBlockSection id="Profile" title="Contact Profile" columns="2" collapsible="True"> <apex:inputField value="{!Contact.CMF_Profile__c}"/> <apex:inputField value="{!Contact.BV_Profile__c}"/> <apex:inputField value="{!Contact.MMF_Profile__c}"/> <apex:inputField value="{!Contact.Swapswire_Profile__c}"/> <apex:inputField value="{!Contact.Trade_Cancellation_CMF__c}"/> <apex:inputField value="{!Contact.BV_Approval__c}"/> <apex:inputField value="{!Contact.BV_Fees__c}"/> <apex:inputField value="{!Contact.Accounting__c}"/> <apex:inputField value="{!Contact.MTS_Data__c}"/> <apex:inputField value="{!Contact.DataFeed_UserName__c}"/> <apex:inputField value="{!Contact.AssistantName}"/> <apex:inputField value="{!Contact.AssistantPhone}"/> <apex:inputField value="{!Contact.Inactive_Contact__c}"/> <apex:pageBlockSectionItem > <apex:actionRegion > <B><apex:outputLabel value="Left the Company"/></B> <apex:outputPanel > <apex:inputCheckbox value="{!Contact.Left_the_Company_Flag__c}"> <apex:actionSupport event="onclick" rerender="Profile" status="status"/> </apex:inputCheckbox> <apex:actionStatus startText="applying value..." id="status"/> </apex:outputPanel> </apex:actionRegion> </apex:pageBlockSectionItem> <apex:pageBlockSection Title="Left the Company" columns="2" rendered="{!Contact.Left_the_Company_Flag__c}"> <apex:inputField value="{!Contact.Moved_to__c}"/> <apex:inputField value="{!Contact.Clone_to_new_Account_without_Profile__c}"/> <apex:inputField value="{!Contact.Comment__c}"/> <apex:inputField value="{!Contact.Clone_to_new_Account_with_Profile__c}"/> </apex:pageBlockSection> </apex:pageBlockSection> <apex:pageBlockSection id="Address2" title="Address" columns="2"> <apex:inputField value="{!Contact.MailingStreet}"/> <apex:inputField value="{!Contact.MailingCity}"/> <apex:inputField value="{!Contact.MailingPostalCode}"/> <apex:inputField value="{!Contact.MailingState}"/> <apex:inputField value="{!Contact.MailingCountry}"/> </apex:pageBlockSection> <apex:pageblocksection id="MTS" Title="MTS Market Configuration" Columns="2"> <apex:inputField value="{!Contact.Linked_Membercodes__c}"/> <apex:inputField value="{!Contact.MTS_CertificateType__c}"/> <apex:pageblocksection id="CMF" Title="CMF Platform" Columns="1"> <apex:inputField value="{!Contact.CMFI_UserID__c}"/> <apex:inputField value="{!Contact.CMFI_User_Profile__c}"/> <apex:inputField value="{!Contact.CMFI_Platform__c}"/> <apex:outputField value="{!Contact.CMF_Software_Signature__c}"/> <apex:outputField value="{!Contact.CMFI_Last_Login__c}"/> <apex:outputField value="{!Contact.Multimarket_SW_version__c}"/> <apex:outputField value="{!Contact.Network_Type__c}"/> </apex:pageblocksection> <apex:pageblocksection id="MMF" Title="MMF Platform" Columns="1"> <apex:inputField value="{!Contact.MMFI_UserID__c}"/> <apex:inputField value="{!Contact.MMFI_User_Profile__c}"/> <apex:inputField value="{!Contact.MMF_Swap_User_ID__c}"/> <apex:inputField value="{!Contact.Swapswire_Account__c}"/> <apex:inputField value="{!Contact.MMFI_Platform__c}"/> </apex:pageblocksection> </apex:pageblocksection> </apex:pageBlock> </apex:form> </apex:page>
and the class :
public class Contactedit { public Contact Contact {get;set;} private ApexPages.standardController controller {get;set;} Public boolean clonawo {get;set;} Public boolean clonawi {get;set;} // recovers from Accounts the billing details public Account accountmoved { get{ if (accountmoved == null) { accountmoved = [select BillingStreet,BillingCity,BillingCountry,BillingPostalCode,BillingState from account where id =: contact.moved_to__c]; } return accountmoved; } set; } public contact clonecontact { get{ //initialize the new contact if (clonecontact == null){ contact t = new contact(); //fill the fields of the new contact record t.firstname = contact.firstname; t.lastname = contact.lastname; t.salutation = contact.salutation; t.accountid = contact.moved_to__c; t.title = contact.Title; t.OwnerId =Userinfo.getUserId(); t.Left_the_Company_flag__c = false; t.MailingStreet = accountmoved.BillingStreet; t.MailingCity = accountmoved.BillingCity; t.MailingCountry = accountmoved.BillingCountry; t.MailingPostalCode = accountmoved.BillingPostalCode; t.MailingState = accountmoved.BillingState; t.Phone = '+00'; System.debug('clonawi = ' + clonawi); if ((contact.Clone_to_new_Account_with_Profile__c == true)|| (clonawi == true)) { t.accounting__c = contact.accounting__c; t.bv_approval__c = contact.bv_approval__c; t.bv_fees__c = contact.bv_fees__c; t.bv_Profile__c = contact.bv_Profile__c; t.CMF_Profile__c = contact.CMF_Profile__c; t.MMF_Profile__c = contact.MMF_Profile__c; t.Swapswire_Profile__c = contact.Swapswire_Profile__c; t.Trade_Cancellation_CMF__C = contact.Trade_Cancellation_CMF__C; } clonecontact = t; } return clonecontact; } set; } public Contactedit(ApexPages.StandardController stdController) { // constructor controller = stdController; this.contact= (contact)stdController.getRecord(); } public void createcontactAndclone(){ // check the ownerId of the position before creating the jobApp & task // the Task cannot be owned by a Queue // String ownerId = checkOwnerIdForQueue(SelectedPosition.OwnerId); // We update the current contact instead of insert try{ //insert contact; contact.Clone_to_new_Account_without_Profile__c = false; contact.Clone_to_new_Account_with_Profile__c = false; update contact; } catch (Exception e){ ApexPages.addMessages(e); } // checks if either clone was selected and of course the company where moved. //if ((contact.Moved_to__c != null) && ((contact.Clone_to_new_Account_without_Profile__c == true)||(contact.Clone_to_new_Account_with_Profile__c== true))) if ((contact.Moved_to__c != null) && ((clonawo == true)||(clonawi == true))) { try{ system.debug('#######' + clonecontact); // insert the new record on contact insert clonecontact; //catch exception } catch (Exception e){ ApexPages.addMessages(e); } } } public PageReference save(){ clonawo = contact.Clone_to_new_Account_without_Profile__c; clonawi = contact.Clone_to_new_Account_with_Profile__c; // updated the Contact and eventually create a new one. createcontactAndclone(); // use the standard controller to perform the save and redirect return controller.view(); } }
@isTest private class Test_Contactedit { public static testMethod void Contactedit_Test() { PageReference pageRef = Page.Contact_Edit_layout; Test.setCurrentPage(pageRef); Contactedit controller = new Contactedit(new ApexPages.StandardController()); String nextPage = controller.save().getUrl(); ApexPages.currentPage().getParameters().put('ContactId', [select id from contact limit 1].id); //extension = new contactedit(new ApexPages.StandardController(cont)); controller.Left_the_company_flag__c=true; controller.Moved_to__c='001R000000bn4Dg'; controller.Clone_to_new_Account_with_profile__c=true; nextPage = controller.save().getUrl(); } }
Save error: Constructor not defined: [ApexPages.StandardController].<Constructor>() Test_Contactedit.cls line 30 Force.com save problem
- elpaso750
- December 16, 2010
- Like
- 0
Unable to fetch Field values of an object
Hi,
I m using a standard controller for my custom object
i want my object's field values to be displayed on visualforce page.
<apex:page showHeader="false" standardStylesheets="false" standardController="Project__c" recordSetVar="ProjectID">
<apex:form >
<apex:pageBlock title="Project Details ">
<apex:pageBlockSection>
<apex:inputField value="{!Project__c.Project_Description__c}"/>
<apex:inputField value="{!Project__c.Maintainance_Type__c}"/>
<apex:inputField value="{!Project__c.Registration_Date__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
here project description is a text field.
i want data of this field to be displayed on visualforce page in text box.
- ipsita19861.2880751705180098E1
- December 15, 2010
- Like
- 0