• Edwards71
  • NEWBIE
  • 100 Points
  • Member since 2012

  • Chatter
    Feed
  • 4
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 15
    Replies

Hi - I have the following visualforce page with controller that allows for multiple row entry on a custom object. I'm stuck on how to get coverage for the Pagereference add() method.  How do I get test data added to the visualforce page so that I can test it? the data is a list passed from the controller..

 

Thanks in advance!

 

Visualforce Page based on custom object Term__C which is the child of the Contract object in a master-detail relationship.

<apex:page controller="multiAddVC" sidebar="false" id="VCPage" showheader="true" tabstyle="contract">
<script language="JavaScript" type="text/javascript">
function CloseAndRefresh(){
window.parent.location.href="/{!$CurrentPage.parameters.id}"; self.close(); }
</script>
<apex:pageMessages />
<apex:form >
<apex:pageBlock title="Virtual Contract - Financial Terms">
<apex:pageBlockButtons >
<apex:pagemessages rendered="true" id="msg2" />
<apex:commandButton value="Add New" action="{!add}" rerender="rows" status="outStatus"/>
<apex:commandButton value="Clear Unsaved" action="{!reset}" rerender="rows" status="outStatus" immediate="true" />
<apex:commandButton action="{!save}" value="Save and Close" oncomplete="javascript&colon;CloseAndRefresh()" rerender="rows,msg2" status="outStatus"/>
</apex:pageBlockButtons>
<apex:pageBlockTable width="100%" align="center" value="{!cexs}" var="c" id="rows" >
<apex:column headervalue="REF">
    <apex:outputText value="{!c.Name}"/>
</apex:column>
<apex:column headerValue="Category">
    <apex:inputField value="{!c.MainCategory__c}" required="true"/>
    </apex:column>
<apex:column headervalue="Sub">
    <apex:inputField value="{!c.Category__c}" required="true"/>
</apex:column>
<apex:column headervalue="Reference">
    <apex:inputField value="{!c.Contract_Reference__c}" required="true"/>
</apex:column>
<apex:column headervalue="Financial Term">
    <apex:inputField value="{!c.Financial_Term__c}" required="true"/>
</apex:column>
<apex:column headervalue="Other Info">
    <apex:inputField value="{!c.Short_Description__c}" style="width: 300px;height:50px"/>
</apex:column>
<apex:column headervalue="Frequency">
    <apex:inputField value="{!c.Frequency__c}" required="true"/>
</apex:column>
<apex:column headervalue="Approved?">
    <apex:outputText value="{!c.Approved__c}"/>
</apex:column>
<apex:column headervalue="Active?">
    <apex:outputText value="{!c.Active_Term__c}"/>
</apex:column>

</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>

 

Controller

public class multiAddVC {
List <Term__c> VCList;
public Id cID = ApexPages.currentPage().getParameters().get('Id'); //grab the Contract ID
public Id getID {get; set;}

public PageReference reset(){ 
VCList = [select name, Contract__c, Category__c,maincategory__c, contract_reference__c,short_description__c,frequency__c,
financial_term__c,active_term__c,approved__c from Term__c where Contract__c =: cID order by createddate ];
return null; 
}
        public List <term__c> getCExs(){
        if(VCList == null) reset();
    Return VCList;
        }        
public void setAccounts(List <Term__c> cexs) {
   VCList = cexs;}
public PageReference save() {//upsert records on save
upsert VCList;
ApexPages.Message myMsg = new ApexPages.message(ApexPages.Severity.Info, 'Records Saved Successfully'); //show confirmation message on save
ApexPages.addMessage(myMsg);
return null;}
public PageReference add() {
VCList.add(New Term__c(Contract__c = cID)); //add records to Virtual contract and associate with current Contract
return null; }
}

 

Unit Test 

@isTest
public class MultiAddVCTests {
static testmethod void MultiAddVCControllerTests(){

// create a new account

account testaccount = new Account(Name='TEST COMPANY',Region__c='EMEA');
insert testaccount;

account testaccount2 = new Account(Name='EMEA REGION',Industry='System use only',Market__c='HQ', Type='Other', Group__c='Global Network Partnerships',Region__c='EMEA');
insert testaccount2;

// create an LFO contact
Contact lfo = new Contact(LastName = 'Hello LFO',business_unit__c='Regional LFO team',accountid=testaccount2.id,email='test2@test.com');

      insert lfo;

// create a BDL contact
Contact bdl = new Contact(LastName = 'Hello BDL',business_unit__c='GNS Business',accountid=testaccount2.id,email='test2@test.com');

      insert bdl;

// Add a new contract

contract c = new Contract();{
//c.status='Not Started';
c.bdl_contact__c=bdl.id;
c.lfo_contact__c=lfo.id;
c.accountid=testaccount.id;
c.companysigneddate=system.today();
c.customersigneddate=system.today();
c.date_rec_d_in_gdi_inbox__c=system.today();
c.startdate=system.today();
c.Project_plan_approved__c=true;
c.name='Test Contract';
c.agreement_type__c='Other';
c.mfr_required__c=false;
c.BETA_test_required__c=false;


insert c;
}

system.assert(true);

// set-up a Virtual contract record

term__c VC = new Term__c(contract__c=c.id,short_description__c='test short',contract_reference__c='test contract ref',approved__c=false,
    contract_language__c='Test contract language',frequency__c='Other',active_term__c='Yes');

insert vc;


// Set up visualforce parameters

PageReference pageRef = Page.MultiAddVC;
PageRef.getParameters().put('id',c.id);

Test.setCurrentPage(pageRef);


MultiAddVC controller = new MultiAddVC();

// create an instance of the controller
// Get a list of Terms already in the system and make sure they are displayed on Page
    
List<Term__c> Terms = ([select name, Contract__c, Category__c,maincategory__c, 
contract_reference__c,short_description__c,frequency__c,financial_term__c,active_term__c,
approved__c from Term__c where Contract__c =:c.id]); 

List<Term__c> VFTerms = controller.getCEXs();

system.assertEquals(Terms,VFTerms);
    
controller.save(); 
controller.add();    
    
 }
}

 

Is it possible to surpress the Notes and Attachments in the Account object from picking up all notes made in other objects that relate to that Account? When viewing the account record the notes are obviously all out of context.

 

I'm guessing I need a VF page with an extension to acheive this?

 

Thanks in advance!

hi - I have a custom object with a checkbox approved__c.  If this checkbox is true I would like a validation rule that would prevent a new task being created on it. Any ideas?

 

thanks in advance!

Hi,

 

I've included an apex:related list for approval history into a Visualforce page being rendered as a PDF however its coming out in a font that is much larger than the font used elsewhere in the visualforce page.

 

Is there a way to adjust the font size of the apex:related list data or do I have to rebuild as a controller extension??

 

<apex:page standardcontroller="Opportunity" showheader="false" contenttype="application/pdf" renderas="pdf" readonly="true" >
     

<apex:relatedList list="ProcessSteps" >
</apex:relatedList>

 

 

Thanks in advance

Hi,

 

I have a pretty simple Apex class which is an extension for a component used in a Visualforce email template.  Since there is no Visualforce page which you'd normally use to test an extension class how do I create a test class? 

 

I've tested several visualforce pages before with no problem, but haven't had to test one with a component, or one which is visualforce email and not a page.

 

 I did create a simple Visualforce page with just the controller on (see code) and used that to test from, however it gives no code coverage .

 

Any ideas??

 

Thanks in advance

Visualforce mark-up:
<apex:page standardcontroller="Contract_Review__c" showheader="false" contenttype="application/pdf"  extensions="ExtFindings" renderas="pdf"  cache="true">
<c:ContractReviewComp thisReviewId="{!Contract_Review__c.id}"/>

   </apex:page>

Component Mark-up:
<apex:component controller="ExtFindings" access="global">
    
    <apex:attribute name="thisReviewID" description="id for current record" type="ID" assignTo="{!thisReviewID}"/>
    
<div style="page-break-after:always;">

        <apex:DataTable value="{!KeyFindings}" var="item" cellpadding="10" rules="all" styleclass="pageblock" >

        
            <apex:column value="{!item.Name}" headervalue="Ref" />

            <apex:column value="{!item.Review_Area__c}" headervalue="Review Area" />
            <apex:column value="{!item.Status__c}" style="{!IF(item.Status__c=='Failed','color:red;font-weight: bold','color:green;font-weight:bold')}" headervalue="Status"/>

            <apex:column value="{!item.What_was_the_finding__c}" headervalue="What was the finding?" />
            <apex:column value="{!item.Type__c}" headervalue="Type" />
              <apex:column value="{!item.What_is_the_financial_Impact__c}" headervalue="What is the financial impact ($)?" />

        </apex:DataTable>
</div>

</apex:component>

Apex Class:
public class ExtFindings {
   
 public ID thisReviewID {get;set;}
           
    Public Review_findings__c [] getKeyfindings () {
        return [Select Name,Review_area__c,Status__c,What_was_the_finding__c,type__c,What_is_the_financial_Impact__c,related_to_review__c
        FROM Review_Findings__c where related_to_review__c = :thisReviewID 
        and include_in_executive_summary__c='Yes' order by Name ASC];
        
        }
}

 

Hi,

 

I've tested a number of controller extensions in Apex Test classes by calling the Visualforce page before, however I haven't had to test a controller extension for a Visualforce email page before and I'm a bit stumped.

 

Since there is no pagereference to call how do I test the Apex class (controller extension)??

 

Thanks

Hi,

 

I'm getting an "Incompatible types since an instance of SObject is never an instance of Contract" when trying to create a very simple visualforce page.

 

Page uses standard contract conroller plus extension which will be used to populate some of the contract fields 'behind the scenes' which the user wont see on the visual force page. The visualforce page will be dealing with new records only.

 

Any ideas what's going on here? I'm stumped and it must be something simple!

 

Thanks in advance

Extension controller:

public class myContract {

    public myContract(ApexPages.StandardController controller) {

    Contract con = (Contract) controller.getRecord();
       
    }


Visualforce page:

<apex:page standardController="Contract" extensions="myContract">
<apex:form >

    <apex:pageBlock title="Historic Contract" mode="edit">
Use this form to input details of an Historic contract that does not need implementation.<p/>
Historic Contracts are needed to support active Virtual contract terms <p/>
 <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" rerender="all"/>
                <apex:commandButton action="{!Cancel}" value="Cancel"/>

            </apex:pageBlockButtons>

  <apex:pageBlockSection title="Contract Details" columns="2">
<apex:inputfield value="{!contract.ContractNumber}" /> <p/>
<apex:inputfield value="{!contract.accountid}" /><p/>
<apex:inputfield value="{!contract.name}" required="true" style="width:350px"/>
<apex:inputfield value="{!contract.StartDate}" required="true"/>
<apex:inputfield value="{!contract.ContractTerm}" required="true"/>
<apex:inputfield value="{!contract.EndDate}" required="true"/>



</apex:pageblocksection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Hi,

 

I have a simple Visualforce page that has two <apex:commandbutton> actions.

 

one button redirects the user to another Visualforce page which works fine.

the other button I want to redirect to the standard object contract page to create a new contract record. I can't seem to get the code right to make this bit work. any ideas?

 

Thanks in advance

<apex:page standardController="Contract" extensions="ExtNewContract">
<apex:form >
<apex:pageBlock title="New Contract Selection" mode="edit">
             <apex:pageBlockButtons >
                <apex:commandButton action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>


  <apex:pageBlockSection title="Contract Details" columns="2">
        <apex:CommandButton action="{!NewImplementation}" value="New Implementation" />
        <apex:CommandButton action="{!Newhistoric}" value="New Historic contract" />
        
</apex:pageblocksection>
</apex:pageblock>

</apex:form>
</apex:page>

 

public class ExtNewContract {

public ExtNewContract(ApexPages.StandardController controller) {
 }

public PageReference NewHistoric() {
        
        PageReference secondPage = Page.Historic_contract;
        secondPage.setRedirect(true);
        
        return secondPage; 
     }

public PageReference NewImplementation() {
        
        PageReference secondPage = new PageReference ('/800/e');
        secondPage.setRedirect(true);        
        return secondPage; 
     }
     
  }

 

 

Hi,

 

I've got an apex:outputlink field linked to a records ID that I want a user to click on and open up the detailed record page. The visualforce page is rendered as a PDF.

 

The ContractNumber appears in blue on the PDF but does nothing when you click on it.

 

Any ideas why? Do I need to specifiy the salesforce URL as its rendered in PDF?

 

Thanks in advance

 

 <apex:pageBlockTable value="{!ContractListing}" var="cl" cellpadding="10" rules="all" styleclass="pageblock" >
                 <apex:column headervalue="Ref">
              <apex:outputLink value="{/!cl.id}" target="_blank">{!cl.ContractNumber}</apex:outputLink>
         </apex:column>

 

 

 

 

 

Hi,

 

I'm trying to extract a list of Task Records that are related to a custom object. I'm using the getkeyprefix to identify the 3 digits so I can use this with WhatId.

 

I'm getting a ' compile error unexpected token GDIPrefix' on the code below. Any ideas why?

 

Thanks in advance!

 

Public Task [] getNotListing() {  
   String GDIPrefix =  GDI_Action__c.sObjectType.getDescribe().getKeyPrefix();
   
   system.debug(GDIPrefix);
   
       return [Select ActivityDate, subject,Description, Contract_reference__c, OwnerID, whoID, whatID
       FROM Task where AccountId = :System.currentPageReference().getParameters().get('id') 
              and ActivityDate < NEXT_YEAR and WhatID Like GDIPrefix order by ActivityDate ASC];
        
        }  

 

Hi,

 

I'm sure there is an easy answer to this but I have tried most things I can think of!

 

I'm using PageBlockTable to iterate over a list of data which is being rendered to PDF.

 

If the list pushes the data onto more than one page the column headers are not repeated.  how can I get the column headers to repeat on each new page?

 

Thanks in advance!

Hi,

 

I have a custom object (contract_review__c) for which I have created a visualforce page. It uses contract_review__c as a standard controller with a custom controller extension (findings).  I'm using PageBlockTable referencing the custom controller extension to iterate over data. 

 

The first three classes of the attached code work fine (note that the related_findings__c object is a related table to Contract_review__c and Contract is the standard object.

 

The last class does not show any records on the visualforce page, even though in debug I can see it has found 12 rows which is the correct number. I've hard coded an account Id for the minute to eliminate that as an issue.

 

Any ideas? Thanks in advance

Controller Extension

public class Findings {

    

    public Findings(ApexPages.StandardController controller) {
    
       }
   
    Public Review_findings__c [] getKeyfindings () {
        return [Select Name,Review_area__c,Status__c,What_was_the_finding__c,type__c,What_is_the_financial_Impact__c,related_to_review__c
        FROM Review_Findings__c where related_to_review__c = :System.currentPageReference().getParameters().get('id') 
        and include_in_executive_summary__c='Yes' order by Name ASC];
        
        }
        
     Public Review_findings__c [] getFailedfindings () {
        return [Select Name,Review_area__c,Status__c,What_was_the_finding__c,type__c,What_is_the_financial_Impact__c,related_to_review__c
        FROM Review_Findings__c where related_to_review__c = :System.currentPageReference().getParameters().get('id') 
        and Status__c='Failed'order by Name ASC];
        
        }
           
       Public Review_findings__c [] getPassedfindings () {
        return [Select Name,Review_area__c,Status__c,What_was_the_finding__c,type__c,What_is_the_financial_Impact__c,related_to_review__c
        FROM Review_Findings__c where related_to_review__c = :System.currentPageReference().getParameters().get('id') 
        and Status__c!='Failed'order by Name ASC];
        
        }
        
        Public Contract [] getContractListing() {       
        return [Select AccountId,Agreement_type__c,StartDate,EndDate,ContractNumber
        FROM Contract where AccountID ='001Z0000003sLj4'];
        
        }  
      }

VF Page code for getContractlisting

<apex:page standardcontroller="Contract_Review__c" showheader="false" contenttype="application/pdf"  extensions="Findings" renderas="pdf"  cache="true">

<apex:pageblock >
 <apex:pageBlockTable value="{!Contractlisting}" var="cl" cellpadding="10" rules="all" styleclass="pageblock" >
    <apex:outputField value="{!cl.StartDate}" />
    <apex:outputField value="{!cl.EndDate}" />
      </apex:pageblockTable>
      </apex:pageblock>

 

Hi,

 

I've included an apex:related list for approval history into a Visualforce page being rendered as a PDF however its coming out in a font that is much larger than the font used elsewhere in the visualforce page.

 

Is there a way to adjust the font size of the apex:related list data or do I have to rebuild as a controller extension??

 

<apex:page standardcontroller="Opportunity" showheader="false" contenttype="application/pdf" renderas="pdf" readonly="true" >
     

<apex:relatedList list="ProcessSteps" >
</apex:relatedList>

 

 

Thanks in advance

Is it possible to surpress the Notes and Attachments in the Account object from picking up all notes made in other objects that relate to that Account? When viewing the account record the notes are obviously all out of context.

 

I'm guessing I need a VF page with an extension to acheive this?

 

Thanks in advance!

hi - I have a custom object with a checkbox approved__c.  If this checkbox is true I would like a validation rule that would prevent a new task being created on it. Any ideas?

 

thanks in advance!

Hi,

 

I have a pretty simple Apex class which is an extension for a component used in a Visualforce email template.  Since there is no Visualforce page which you'd normally use to test an extension class how do I create a test class? 

 

I've tested several visualforce pages before with no problem, but haven't had to test one with a component, or one which is visualforce email and not a page.

 

 I did create a simple Visualforce page with just the controller on (see code) and used that to test from, however it gives no code coverage .

 

Any ideas??

 

Thanks in advance

Visualforce mark-up:
<apex:page standardcontroller="Contract_Review__c" showheader="false" contenttype="application/pdf"  extensions="ExtFindings" renderas="pdf"  cache="true">
<c:ContractReviewComp thisReviewId="{!Contract_Review__c.id}"/>

   </apex:page>

Component Mark-up:
<apex:component controller="ExtFindings" access="global">
    
    <apex:attribute name="thisReviewID" description="id for current record" type="ID" assignTo="{!thisReviewID}"/>
    
<div style="page-break-after:always;">

        <apex:DataTable value="{!KeyFindings}" var="item" cellpadding="10" rules="all" styleclass="pageblock" >

        
            <apex:column value="{!item.Name}" headervalue="Ref" />

            <apex:column value="{!item.Review_Area__c}" headervalue="Review Area" />
            <apex:column value="{!item.Status__c}" style="{!IF(item.Status__c=='Failed','color:red;font-weight: bold','color:green;font-weight:bold')}" headervalue="Status"/>

            <apex:column value="{!item.What_was_the_finding__c}" headervalue="What was the finding?" />
            <apex:column value="{!item.Type__c}" headervalue="Type" />
              <apex:column value="{!item.What_is_the_financial_Impact__c}" headervalue="What is the financial impact ($)?" />

        </apex:DataTable>
</div>

</apex:component>

Apex Class:
public class ExtFindings {
   
 public ID thisReviewID {get;set;}
           
    Public Review_findings__c [] getKeyfindings () {
        return [Select Name,Review_area__c,Status__c,What_was_the_finding__c,type__c,What_is_the_financial_Impact__c,related_to_review__c
        FROM Review_Findings__c where related_to_review__c = :thisReviewID 
        and include_in_executive_summary__c='Yes' order by Name ASC];
        
        }
}

 

Hi,

 

I've tested a number of controller extensions in Apex Test classes by calling the Visualforce page before, however I haven't had to test a controller extension for a Visualforce email page before and I'm a bit stumped.

 

Since there is no pagereference to call how do I test the Apex class (controller extension)??

 

Thanks

Hi,

 

I'm getting an "Incompatible types since an instance of SObject is never an instance of Contract" when trying to create a very simple visualforce page.

 

Page uses standard contract conroller plus extension which will be used to populate some of the contract fields 'behind the scenes' which the user wont see on the visual force page. The visualforce page will be dealing with new records only.

 

Any ideas what's going on here? I'm stumped and it must be something simple!

 

Thanks in advance

Extension controller:

public class myContract {

    public myContract(ApexPages.StandardController controller) {

    Contract con = (Contract) controller.getRecord();
       
    }


Visualforce page:

<apex:page standardController="Contract" extensions="myContract">
<apex:form >

    <apex:pageBlock title="Historic Contract" mode="edit">
Use this form to input details of an Historic contract that does not need implementation.<p/>
Historic Contracts are needed to support active Virtual contract terms <p/>
 <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" rerender="all"/>
                <apex:commandButton action="{!Cancel}" value="Cancel"/>

            </apex:pageBlockButtons>

  <apex:pageBlockSection title="Contract Details" columns="2">
<apex:inputfield value="{!contract.ContractNumber}" /> <p/>
<apex:inputfield value="{!contract.accountid}" /><p/>
<apex:inputfield value="{!contract.name}" required="true" style="width:350px"/>
<apex:inputfield value="{!contract.StartDate}" required="true"/>
<apex:inputfield value="{!contract.ContractTerm}" required="true"/>
<apex:inputfield value="{!contract.EndDate}" required="true"/>



</apex:pageblocksection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Hi,

 

I have a simple Visualforce page that has two <apex:commandbutton> actions.

 

one button redirects the user to another Visualforce page which works fine.

the other button I want to redirect to the standard object contract page to create a new contract record. I can't seem to get the code right to make this bit work. any ideas?

 

Thanks in advance

<apex:page standardController="Contract" extensions="ExtNewContract">
<apex:form >
<apex:pageBlock title="New Contract Selection" mode="edit">
             <apex:pageBlockButtons >
                <apex:commandButton action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>


  <apex:pageBlockSection title="Contract Details" columns="2">
        <apex:CommandButton action="{!NewImplementation}" value="New Implementation" />
        <apex:CommandButton action="{!Newhistoric}" value="New Historic contract" />
        
</apex:pageblocksection>
</apex:pageblock>

</apex:form>
</apex:page>

 

public class ExtNewContract {

public ExtNewContract(ApexPages.StandardController controller) {
 }

public PageReference NewHistoric() {
        
        PageReference secondPage = Page.Historic_contract;
        secondPage.setRedirect(true);
        
        return secondPage; 
     }

public PageReference NewImplementation() {
        
        PageReference secondPage = new PageReference ('/800/e');
        secondPage.setRedirect(true);        
        return secondPage; 
     }
     
  }

 

 

Hi,

 

I've got an apex:outputlink field linked to a records ID that I want a user to click on and open up the detailed record page. The visualforce page is rendered as a PDF.

 

The ContractNumber appears in blue on the PDF but does nothing when you click on it.

 

Any ideas why? Do I need to specifiy the salesforce URL as its rendered in PDF?

 

Thanks in advance

 

 <apex:pageBlockTable value="{!ContractListing}" var="cl" cellpadding="10" rules="all" styleclass="pageblock" >
                 <apex:column headervalue="Ref">
              <apex:outputLink value="{/!cl.id}" target="_blank">{!cl.ContractNumber}</apex:outputLink>
         </apex:column>

 

 

 

 

 

Hi,

 

I'm trying to extract a list of Task Records that are related to a custom object. I'm using the getkeyprefix to identify the 3 digits so I can use this with WhatId.

 

I'm getting a ' compile error unexpected token GDIPrefix' on the code below. Any ideas why?

 

Thanks in advance!

 

Public Task [] getNotListing() {  
   String GDIPrefix =  GDI_Action__c.sObjectType.getDescribe().getKeyPrefix();
   
   system.debug(GDIPrefix);
   
       return [Select ActivityDate, subject,Description, Contract_reference__c, OwnerID, whoID, whatID
       FROM Task where AccountId = :System.currentPageReference().getParameters().get('id') 
              and ActivityDate < NEXT_YEAR and WhatID Like GDIPrefix order by ActivityDate ASC];
        
        }  

 

Hi,

 

I'm sure there is an easy answer to this but I have tried most things I can think of!

 

I'm using PageBlockTable to iterate over a list of data which is being rendered to PDF.

 

If the list pushes the data onto more than one page the column headers are not repeated.  how can I get the column headers to repeat on each new page?

 

Thanks in advance!