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
DeclanDeclan 

Apex class

I am trying to design a UI for a custom object .
The steps involved are 1.Create a new opportunity 2.Create a new custom object(Reference__c) within opportunity  3.Select Custom object from a lookupfield (Test_Service_Item__c) within Reference. It is the fields in the (Test_Service_Item__c) that the UI is for.

My VF code is :
<apex:page standardController="Test_Service_Item__c" >
<apex:pageMessages ></apex:pageMessages>
    <apex:pageBlock id="thePageBlock" >
        <apex:pageBlockSection title="test" columns="1" >
        <apex:form >    
     <apex:inputfield value="{!Test_Service_Item__c.Reference__c}"/>
        <apex:inputfield value="{!Test_Service_Item__c.name}"/>
         <apex:inputfield value="{!Test_Service_Item__c.Customer_OnSite__c}"/>
          <apex:inputfield value="{!Test_Service_Item__c.Required_Item__c}"/>
           <apex:inputfield value="{!Test_Service_Item__c.Show_Price_On_Quote__c}"/>
        <apex:inputfield value="{!Test_Service_Item__c.Include_in_Quote__c}"/>
         <apex:inputfield value="{!Test_Service_Item__c.Overall_Sort_Order__c}"/>
         <apex:inputfield value="{!Test_Service_Item__c.Price__c}"/>
         <apex:inputfield value="{!Test_Service_Item__c.Answer__c}"/>
         <apex:inputfield value="{!Test_Service_Item__c.Sort_Order__c}"/>
         <apex:inputfield value="{!Test_Service_Item__c.Std_Sort_Order__c}"/>   
        <apex:commandButton action="{!save}" value="save"/>       
         </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

This is dispalying the fields but they are blank. Do i need Apex class to have the values of the object appearing in VF page?
Amit VaidyaAmit Vaidya
For StandardController no need to write apex class for fetching value. For your above page to display values, just provide the ID in the URL, so lets say if your page name is TestServiceItem so in URL you needs to provide the ID of Test_Service_Item__c record as below:

https://base_url/apex/TestServiceItem?id=15_or_18_digit_id_of_record

Thanks,
Amit
DeclanDeclan
Hi Amit That worked perfectly. Is there a way I can use the reference id to display all the service item fields on that reference ? Regards, Declan Declan Tannian ANECTO
Amit VaidyaAmit Vaidya
Hi,

Can you please rephrase your question? I didn't get your exact requirement.
DeclanDeclan
Amit Can I use the ID reference to display the list of the test service items? By using the id of the test service item it gives me just one record. Does this make sense ? Regards, Declan Declan Tannian ANECTO
Amit VaidyaAmit Vaidya
If you want to display list of records:
 
<apex:page standardController="Test_Service_Item__c" recordSetVar="items" sidebar="false">
	<apex:pageMessages ></apex:pageMessages>
	<apex:pageBlock id="thePageBlock" >
		<apex:pageBlockTable value="{!items}" var="i">
			<apex:form >
				<apex:column value="{!i.Reference__c}"/>
				<apex:column value="{!i.name}"/>
			</apex:form>
		</apex:pageBlockTable>
	</apex:pageBlock>
</apex:page>

Sorry if again you required something different and I comes up diffrent.

Thanks,
Amit
DeclanDeclan
Thanks Amir This gives me a list of references. What I am trying to achieve is to isolate one reference and the list of service items for that reference. I have attached a screenshot. I’m not sure if you can see this. Regards, Declan Declan Tannian ANECTO
Amit VaidyaAmit Vaidya
Sorry. I am not able to see screenshot. Just wanted know, did you get your answer from above discussions?
DeclanDeclan
Unfortunately not. I have one reference record and multiple test service item records. I need to be able to view and edit all the test service item records for a reference record. What I have so far just gives me a list of reference records but not the test service item records. Regards, Declan Declan Tannian ANECTO
Amit VaidyaAmit Vaidya
Hi Declan,

I tried this for you by taking example of Account(i.e. yours Opportunity) and Contacts(i.e yours Test_Service_Item__c). Please update this by taking your objects:
 
Apex Page:

<apex:page controller="accountcontact">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockTable value="{!accounts}" var="acc" columns="3">
				<apex:column value="{!acc.Name}"/>
				<apex:column >
					<apex:pageBlockTable value="{!acc.contacts}" var="con">
						<apex:column value="{!con.Name}"/>
					</apex:pageBlockTable>
				</apex:column>
			</apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Controller Class:

public class accountcontact{
	public list<account> acclist = new list<account>();
	public accountcontact(){
		for(account a:[SELECT CreatedbyID,Account.Name,(SELECT name,Contact.FirstName, Contact.LastName FROM Account.Contacts) FROM Account]){
			acclist.add(a);
		}
	}
	public list<account> getaccounts(){
		return acclist;
	}
}

Let me know if it works for you.

Thanks,
Amit
DeclanDeclan
Thanks again Amit With my class I am getting the following error “Error: dec1 Compile Error: unexpected token: 'FROM' at line 4 column 54” public class dec1{ public list acclist = new list(); public dec1(){ for(reference__c a:[SELECT Name,(SELECT name, FROM test_service_item__c]){ acclist.add(a); } } public list gettest_service_item__c(){ return acclist; } } This is VF page: Declan
Amit VaidyaAmit Vaidya
Try this,
 
public class dec1{
	public list acclist = new list();
		public dec1(){ 
			for(reference__c a:[SELECT Name,(SELECT name FROM test_service_item__c]){
				acclist.add(a); 
			}
		}
		public list gettest_service_item__c(){
			return acclist; 
		} 
}

 
Amit VaidyaAmit Vaidya
This is the whole converted code as per your objects:
 
Apex Page:

<apex:page controller="dec1">
	<apex:form >
		<apex:pageBlock >
			<apex:pageBlockTable value="{!Opps}" var="op" columns="3">
				<apex:column value="{!op.Name}"/>
				<apex:column >
					<apex:pageBlockTable value="{!op.test_service_items__r}" var="tsi">
						<apex:column value="{!tsi.Name}"/>
					</apex:pageBlockTable>
				</apex:column>
			</apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Controller Class:

public class dec1{
	public list<Opportunity> opplist = new list<Opportunity>();
	public dec1(){
		for(Opportunity o:[SELECT CreatedbyID,Name,(SELECT name FROM Opportunity.test_service_items__r) FROM Opportunity]){
			opplist.add(o);
		}
	}
	public list<Opportunity> getOpps(){
		return opplist;
	}
}

 
DeclanDeclan
Amir Thanks again. I tried the code you supplied. This is giving me the opportunity record and the reference records. What I am trying to achieve is to get the reference record and the test service item records. I tried to modify your code but I am having no luck. Declan
Amit VaidyaAmit Vaidya
Can you please send me your object diagram?
DeclanDeclan
Amit I’m not sure what you mean by object diagram. Opportunity Reference (Master-Detail Relationship from Reference to Opportunity) Test Service item (Master-Detail Relationship from Test Service Item to Reference) Is this what you are looking for ? Declan
DeclanDeclan
Amit The following makes code lets me view the information I need. How would I make these fields editable ? Would I need to write a custom controller for saving? Apex: public with sharing class declan17 { public final ApexPages.StandardController c; public Opportunity opp { get { return [SELECT id, Owner.name, Account.Name FROM Opportunity WHERE id = :c.getID()]; } set; } public Boolean lastPageBreak { get; set; } public declan17(ApexPages.StandardController c) { // this.opp = (Opportunity)c.getRecord(); this.c = c; System.debug(System.currentPageReference().getParameters().get('lastPageBreak')); if(System.currentPageReference().getParameters().get('lastPageBreak') == 'true') { System.debug('loop true'); this.lastPageBreak = true; } else { System.debug('loop false'); } } public List referenceObjs{ get{ if (referenceObjs == null) { referenceObjs = new List(); List refs = [Select Id, name, Name_and_Order_Number__c, Timepoint__c, Referenced_Standard_Names__c, price__c, Quantity__c, Service_Type__c, Comments__c, Page_Break_Before_Table__c, Reference_Row_Line_Height__c, (SELECT Name, Answer__c, Currency__c, Customer_On_Site_Text__c, Price_On_Quote__c, Required_Item_Text__c, Include_in_Quote__c, Price__c, Required_Status_Text__c, Show_Price_On_Quote__c FROM Test_Service_Items__r WHERE Include_in_Quote__c = true ORDER BY Overall_Sort_Order__c ASC) From Reference__c where Opportunity_Name__c=:c.getID() ORDER BY Sort_Order__c ASC]; for(Reference__c r : refs) { System.debug(r); System.debug(r.Test_Service_Items__r); Reference record = new reference(r, r.Test_Service_Items__r); referenceObjs.add(record); } } return referenceObjs; } set; } public List referenceObjs_answers{ get{ // perform the logic to find the Reviews that have not yet been completed for the current Position if (referenceObjs_answers == null) { referenceObjs_answers = new List(); List refs = [Select Id, name, Name_and_Order_Number__c, Timepoint__c, Referenced_Standard_Names__c, price__c, Quantity__c, Service_Type__c, Comments__c, Actual_Price_Text__c, Top_Margin__c, Title_Row_Line_Height__c, Page_Break_Before_Table__c, Reference_Row_Line_Height__c, (SELECT Name, Answer__c, Currency__c, Customer_On_Site_Text__c, Price_On_Quote__c, Required_Item_Text__c, Include_in_Quote__c, Price__c, Required_Status_Text__c, Show_Price_On_Quote__c FROM Test_Service_Items__r ORDER BY Overall_Sort_Order__c ASC) From Reference__c where Opportunity_Name__c=:c.getID() ORDER BY Sort_Order__c ASC]; for(Reference__c r : refs) { System.debug(r); System.debug(r.Test_Service_Items__r); Reference record = new reference(r, r.Test_Service_Items__r); referenceObjs_answers.add(record); } } return referenceObjs_answers; } set; } public class reference { public Reference__c ref {get; set;} public List items { get; set; } public reference(Reference__c ref, List items) { this.ref = ref; this.items = items; } } } Vf page:
 
{!ref.ref.Name_and_Order_Number__c} {!ref.ref.Timepoint__c}
{!tsi.Name}
 

  

Declan From: Declan Tannian [mailto:dtannian@anecto.com] Sent: 17 June 2016 14:35 To: 'reply' Subject: RE: (Salesforce Developers): New reply to your question. Amit I’m not sure what you mean by object diagram. Opportunity Reference (Master-Detail Relationship from Reference to Opportunity) Test Service item (Master-Detail Relationship from Test Service Item to Reference) Is this what you are looking for ? Declan
Amit VaidyaAmit Vaidya
Yes Declan, You need to write the action function for saving the changes made in the editable fields. You can write that in the same dec1 class that I have provided above or else if the code you pasted above is working for you then just write that save action function inside the declan17 class. Once done, you can call that function on page through commandbutton tag by function name to its action attribute.

Thanks,
Amit