1

I'm not sure why it's failing on this particular field and I have couple of other fields with same inputField, what I'm doing wrong here?

Wrong type for attribute <c:invoicedetail InvoiceAmount="{!myinvoice.Invoice_Amount__c}">. Expected Invoice__c, found BigDecimal (Line: 1, Column: -1)

Here is my very simple VF component:

<apex:attribute name="InvoiceAmount" description="Invoice Amount" type="invoice__c" required="true"/>
<many other inputfields here....
<apex:inputField id="in" value="{!InvoiceAmount.Invoice_Amount__c}"/>

VF page:

<c:mycomponent  InvoiceAmount="{!myinvoice.Invoice_Amount__c}"

Controller:

public with sharing class InvoiceController {
    public InvoiceController() {
       Invoice__c myinvoice = [/*SOQL*/];
    }
}
0

1 Answer 1

3

You need to pass the record instead of its field. Since you seem to reference other fields on the record, this is the route you should take to fix your issue. I would rename your attribute to invoice or invoiceRecord instead.

<c:mycomponent invoice="{!myInvoice}" />

Then your component would be:

<apex:attribute
    name="invoice"
    description="Invoice Record"
    type="Invoice__c"
    required="true"/>
<apex:inputField value="{!invoice.Invoice_Amount__c}" />
<apex:inputField value="{!invoice.AnotherField__c}" />
9
  • what is the best practice in this situation?
    – Nick
    Feb 29, 2016 at 14:43
  • if i try to change to type="Decimal" in the VF component then I'm getting this error <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable
    – Nick
    Feb 29, 2016 at 14:48
  • I do not think so, I have posted VF page, VF Comp, and Controller, why do you think I'm giving incomplete picture
    – Nick
    Feb 29, 2016 at 14:51
  • @AbuHamzah You must use type="Invoice__c" because you have many inputField tags.
    – Adrian Larson
    Feb 29, 2016 at 14:54
  • I have exactly how you have laid-out and when I have this in my VF page <c:mycomponent invoice="{!myInvoice}" /> then getting this error unknown property create apex property invoice.invoice__c error
    – Nick
    Feb 29, 2016 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .