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
Ramesh VaratharajRamesh Varatharaj 

VF Component unknown property 'string.Name'

I am writing an controller and VF component to email opportunitylineitemschedule details as an attachment. I am able to include schedule details to the attachment, but i am not able to include the opportunitylineitem's field in the same table. 

My requirement - for each line item schedule row, i would like to have one column populating the opportunitylineitem.Product_Name__c values. I am getting unknown property error 'String.Product_Name__c' if i try to add this field. 
my controller: 
public class emailtemplatev2{
    public emailtemplatev2() {    
    }
  List<OpportunityLineItemSchedule> revenue = new List<OpportunityLineItemSchedule>(); 
   public Id opportunityId {get;set;} 
   public List<OpportunityLineItemSchedule> getrevenue()
   { 
       revenue=[Select OpportunityLineItemId, CurrencyIsoCode, ScheduleDate,Revenue                           
                 from OpportunityLineItemSchedule where OpportunityLineItemId IN (Select ID from OpportunityLineItem 
                 where OpportunityId =:opportunityid )  ];
     return revenue;
        }  
}


VF Component: 
<apex:component controller="emailtemplatev2" access="global">
    
   
    <apex:attribute name="AcctId" type="Id" description="Id of the account" assignTo="{!opportunityId}"/>
    <table border = "2" cellspacing = "0" >
        <tr>
            <td>Product</td>
            <td>Forecast Period</td>
            <td>Currency</td>   
            <td>Amount</td> 
                         
        </tr>
        <apex:repeat value="{!revenue}" var="o">
        <tr>
            <td>{!o.OpportunityLineItemId.Product_Name__c}</td> //having issue in this line
            <td>   
            <apex:outputText value="{0,date,MMM, yyyy}">
            <apex:param value="{!o.ScheduleDate}" /> 
            </apex:outputText>
            </td>  
        
            <td>{!o.CurrencyIsoCode}</td>  
            <td>{!o.Revenue}</td> 
                        
        </tr>
        </apex:repeat>        
    </table>
</apex:component>


 
Best Answer chosen by Ramesh Varatharaj
Alexander TsitsuraAlexander Tsitsura
Hello Ramesh,

"{!o.OpportunityLineItemId}" - a string because this variable represents id of the record. If you want to get the related field on OpportunityLineItem, you need query this field in the controller and use relation like that "{!o.OpportunityLineItem.Product_Name__c}". 

If it helped you, then please select it the best answers it will help outer also.

Thanks,
Alex

All Answers

Alexander TsitsuraAlexander Tsitsura
Hello Ramesh,

"{!o.OpportunityLineItemId}" - a string because this variable represents id of the record. If you want to get the related field on OpportunityLineItem, you need query this field in the controller and use relation like that "{!o.OpportunityLineItem.Product_Name__c}". 

If it helped you, then please select it the best answers it will help outer also.

Thanks,
Alex
This was selected as the best answer
Ramesh VaratharajRamesh Varatharaj
Thanks Alex for the quick response. I understood the issue, but having challenge in querring the field. 

If i add OpportunityLineItemId.Product_Name__c in the querry - i am getting relationship error. can you advise how to include this field in the querry?

revenue=[Select OpportunityLineItemId.ProductName__c, CurrencyIsoCode, ScheduleDate,Revenue                           
                 from OpportunityLineItemSchedule where OpportunityLineItemId IN (Select ID from OpportunityLineItem 
                 where OpportunityId =:opportunityid )  ];
     return revenue;
Alexander TsitsuraAlexander Tsitsura
Ramesh, you need query OpportunityLineItem.Product_Name__c, not OpportunityLineItemID.Product_Name__c

Thanks,
Alex
Ramesh VaratharajRamesh Varatharaj
wow...it worked boss. Thanks a lot