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
Simon WhightSimon Whight 

Visualforce Component - where am I going wrong?

At the moment, I'm trying to "hello world" this component to put into a VF email. I am massively struggling though.

Here is what I have. First the Apex - this is to get the Contract whose detail is needed, the ID I am planning to get from the Contract record where the "Send Email" button will be hosted:
public class findContract {
  
public Id conID {get; set;}

    Public List<Contract> currentcontract = new List<Contract>();

    public List<Contract> findCurrentContract() {
        currentcontract = [SELECT Id, StartDate, Business_Type__c, Affinity__c, ContractTerm,  CompanySigned.name, CompanySignedDate, CustomerSigned.name, CustomerSignedDate, CustomerSignedTitle, 
        EndDate, Services_Taken_AI_Only__c, Services_Taken_AI_Only_HS__c, Services_Taken_Advice_Only__c, Services_Taken_Advice_Only_HS__c, Services_Taken_Franchise_Comp_EL__c, 
        Services_Taken_Franchise_Comp_HS__c, Services_Taken_Consultancy__c, Services_Taken_Franchise_Entry_EL__c, Services_Taken_Env__c, 
        Services_Taken_eRAMS__c, Services_Taken_FRA__c, Services_Taken_HS__c, Services_Taken_SBP__c, Services_Taken_Training__c, Services_Taken_JIT__c, H_S_Notes__c, 
        Finance_Notes__c, PEL_Notes__c, SpecialTerms FROM Contract WHERE Id = :conID];   
          

        return currentcontract ;
        
        }
    
}
Then we have the Component, currently this will not save with this error ( Error: Could not resolve the entity from <apex:outputField> value binding '{!con.ContractTerm}'. <apex:outputField> can only be used with SObjects, or objects that are Visualforce field component resolvable. )

I'm just trying to get an example 4 fields to put into the component!

I haven't got as far as putting the component in the VF email because I can't do the above. I'm expecting to have something like:
 
<c:DisplayContractDetails ContractID="{!Contract.Id}"/> 

*** I'm assuming I'll have to do something a bit more advanced to pull the current records id

I can see what I am trying to do logically, my skills are letting me down. Can anyone help?

Thanks and Happy New Year!


 
Simon WhightSimon Whight

Finally got it to save, nothing is coming back in my table though.
 
<apex:component controller="findContract" access="global">
    <apex:attribute name="ContractId" description="This is the Contract Id." type="Id" assignTo="{!conID}"/>     
    <table border="1">
        <tr>
            <td><apex:outputText value="Contract Term"/></td>
            <td><apex:outputText value="Start Date"/></td>
            <td><apex:outputText value="Business Type"/></td>
            <td><apex:outputText value="Affinity"/></td>
        </tr>  
    <apex:repeat value="{!currentcontract}" var="con" id="theRepeat">
        <tr>
            <td><apex:outputField value="{!con.ContractTerm}"/></td>
            <td><apex:outputField value="{!con.StartDate}"/></td>
            <td><apex:outputField value="{!con.Business_Type__c}"/></td>
            <td><apex:outputField value="{!con.Affinity__c}"/></td>
        </tr>                
    </apex:repeat>
    </table>
</apex:component>


conID is hardcoded at the moment and should be returning something.

It is as if there is nothing happening in the apex.