+ Start a Discussion
timrnicholstimrnichols 

Contacts Test Class Confusion


I'm attempting to build a test class for a connection between two contacts using the contact connector.  The idea is using VF to show the contacts on both sides of the contact for a many to many contact relationship.

Problem is I'm not sure of the process for the test case.   I assume the steps are:

-Create a instance of the object between the two contacts
-Create a contact and "related contact" and populate it
-The test to see if I can see the Contact2 ID from Contact1.  

Works fine in Sandbox but not sure how to write up the test as sometimes Eclipse give me the error "Error in code" but without specifics, but can't get it to pass 75%. 

Any advice would be super helpful.  

Some of this code was taken from the NPSF chat.

Code:
public class Contact_Connection {
 
   private final Contact cont;
    
    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    
    public Contact_Connection(ApexPages.StandardController stdController) {
        this.cont = (Contact)stdController.getRecord();
    } 

public String getName(){
       return 'Inbound and Outbound Connections';
 }
      public list <SFDC_Contact_Connector__c> getConnections() {
        
        List <SFDC_Contact_Connector__c> connections;
        
        connections = [select id, name, Contact__r.name,
  Related_Contact__r.name, Relationship__c, Description__c,
  Related_Organization__r.name, Related_Organization_Role__c from
  SFDC_Contact_Connector__c where Contact__c
  = :System.currentPageReference().getParameters().get('id') OR
  Related_Contact__c = :System.currentPageReference().getParameters().get('id')];
  
        return connections;
 
 }

 

Code:
<apex:page standardController="Contact" extensions="Contact_Connection">
 <apex:pageBlock title="This contact has made the following connections" helpTitle="" helpUrl="">
  <apex:pageBlockTable value="{!connections}" var="connection"
    id="cList" width="100%">
   <apex:column >
     <apex:facet name="header">Contact</apex:facet>
     <apex:outputLink value="/{!if(LEFT(connection.Contact__c,15) ==
            $CurrentPage.parameters.id,
            if(not(isnull(connection.Related_Contact__c)),
            connection.Related_Contact__c, connection.Related_Organization__c),
            connection.Contact__c)}">{!if(LEFT(connection.Contact__c,15)==
            $CurrentPage.parameters.id,
            if(not(isnull(connection.Related_Contact__c)),
            connection.Related_Contact__r.name,
            connection.Related_Organization__r.name),
            connection.Contact__r.name)}
    </apex:outputLink>
  </apex:pageBlockTable>
 </apex:pageBlock>
</apex:page>

 





Message Edited by timrnichols on 09-26-2008 03:30 PM
Sam.arjSam.arj

 view this post and see if it helps with your case:

http://salesforcesource.blogspot.com/2008/09/geting-good-test-coverage-on-vf-pages.html

http://salesforcesource.blogspot.com/2008/09/geting-good-test-coverage-on-vf-pages.html


Sam.arjSam.arj
 Hi Tim,

 Check this post out It will help you come over the problem.

 http://salesforcesource.blogspot.com/2008/09/testing-your-controller-extentions.html

 Good luck!