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
SFDC AVINASHSFDC AVINASH 

Simple Item and Description Page.

Hi All i am trying to build a simple page where i list all the item avialbe, and next to each item there will be button to show a description of the item. When user press description button bellow the item descriptions should be display. Items and Descriptions are from different objects they are related by lookup (dont want Master child relation).

I am facing few issues.
1. How can i acheave the fuction when user press detail button, details are displayed.
2. Since Item and desciptions are related i tried joined SOQL to retrive the data from both the tables but i am not able to disply the Description object records.
(Note: Bellow code i replaced all the name of the Item object with Projec__c and Detail with Resource__c)
 
<apex:page controller="Main_Timesheet" sidebar="false" action="{!onloadfunction}">
     <apex:variable var="rownum" value="{!0}" />
    <apex:form >
        
      <apex:actionRegion >
             <apex:actionSupport event="onchange" reRender="entrytable"/>
            <apex:outputPanel id="entrytable" rendered="{!NOT(ISNULL(entrylist))}">
                 
                <apex:dataTable cellspacing="15" value="{!entrylist}" var="Project">                 
                    <apex:column >
                        <apex:variable var="rownum" value="{!rownum + 1}"/> 
                        <apex:outputText >
                        {!rownum}
                        </apex:outputText>
                    </apex:column>
                     <apex:column headervalue="QB#">
                <apex:inputfield value="{!Project.QB__c}" style="width:100px;" required="true" rendered="{!(ISNULL(Project.QB__c))}"/>
                <apex:outputfield value="{!Project.QB__c}" style="width:1300px;" /> 
                         
                    </apex:column>
				
                 
                 <apex:column headervalue="Project Desc">
                <apex:inputfield value="{!Project.Description__c}" style="width:100px;" required="true" rendered="{!(ISNULL(Project.Description__c))}"/>
                   <apex:outputfield value="{!Project.Description__c}" style="width:300px;"/>  
                    </apex:column>
                   
                 
                 <apex:column headervalue="Delivery Date">
                <apex:inputfield value="{!Project.Delivery_Date__c}" style="width:100px;" required="true" rendered="{!(ISNULL(Project.Delivery_Date__c))}" />
                    <apex:outputfield value="{!Project.Delivery_Date__c}" style="width:300px;"/>
                    </apex:column>
                 <apex:column >
                 <apex:commandlink action="{!Deleterow}" immediate="true"> <apex:param name="tentryid" value="{!Project.Id}"/> <apex:param name="rownumber" value="{!rownum}"/><apex:commandbutton value="Delete" /> </apex:commandlink>
                 </apex:column>
                    
               </apex:dataTable>
                     
                    </apex:outputPanel>
         
           
            <apex:commandButton value="Create New" action="{!CreateNew}"/>
          <apex:commandButton value="Save" action="{!Save}"/>
        </apex:actionRegion>
    </apex:form> 
</apex:page>
 
public class Main_Timesheet {
   // Public List<Projects__c> tentries;
   Public List<SObject> tentries;
	public Projects__c delattendeeList;
    Public List<Resource__c> ResourceList;


    public void onloadfunction(){
      //tentries = [select Id,QB__c,Description__c,Delivery_Date__c from Projects__c];
        tentries =  [SELECT Id, Name,QB__c,Description__c,Delivery_Date__c, (SELECT Project_Name__c FROM Resources__r) FROM Projects__c];
    }            

    public List<Projects__c> getentrylist(){
    if (tentries!=NULL && tentries.size()>0) 
       return tentries;
    else 
       return null;       
	}


// Create a new Project record.    
    Public void CreateNew(){
        system.debug('Add new project');
        Projects__c newProject = new Projects__c();
        tentries.add(newProject);
    }
    

    public PageReference save(){
        UPSERT tentries;
        return null;
    }    
    
     public PageReference Deleterow(){
     	Integer rowno  = Integer.valueOf(ApexPages.currentPage().getParameters().get('rownumber'));
		//delattendeeList = tentries.get(rowno-1);
		tentries.remove(rowno-1);
		UPSERT tentries;
        return null;
    }    
}

Though i am using "
tentries = [SELECT Id, Name,QB__c,Description__c,Delivery_Date__c, (SELECT Project_Name__c FROM Resources__r) FROM Projects__c];" i am not able to disply "Project_Name__c"

Thanks for your wonderful suggetions :) 
Shailesh DeshpandeShailesh Deshpande
Hi Avinash,

You might want to change the code and perform the query from child to parent instead of using a subquery as you stated above. This way you will have individual resources record on each row.
public void onloadfunction(){
     
     tentries = [Select Id, Project_Name__c, Projects__r.Id, Projects__r.Name, Projects__r.Description__c, Projects__r.QB__c, Projects__r.Delivery_Date__c from Resources__c];

    }
Make sure you change the List type and the related methods referencing tentries.

Other way here is that you can continue the same way as you have coded, but the syntax you used for displaying description is not correct. It shoud be as below:
 
<apex:column headervalue="Project Desc">

<apex:repeat name="{!Project.Resources__r" var="resources">
                <apex:inputfield value="{!resources.Description__c}" style="width:100px;" required="true" rendered="{!(ISNULL(resources.Description__c))}"/>

                   <apex:outputfield value="{!resources.Description__c}" style="width:300px;"/> 
<br/>
</apex:repeat>

 </apex:column>

Since Resources is a child object for Project, it will have multiple records for a single project. Hence the subquery will return a list, and wwe need to iterate over each of the resources record to show its description. I am adding a 'br' tag in the end to distinguish each of the description.

To Show/hide the description, you can use a button and have onclick javascripteven to toggle.

Thanks,
Shailesh.
 
SFDC AVINASHSFDC AVINASH
Thank you so much Shailesh for your wonderful reply. But unfortunately the first solution given by you am not able to use, as its throwing me a error even when i try to run it on a query editor. Its saying as bellow, Projects__r.Delivery_Date__c from Resources__c ^ ERROR at Row:1:Column:144 sObject type 'Resources__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. Could you please help me to resolve the query? Your second solution si working fine but i am more interested to use Query language as i want to enhance my skill on that area. Also if you have any good materiel for learing complex SOQL query it would be great help for me. Thanks, Avinash Upadhya
Shailesh DeshpandeShailesh Deshpande
The object should be Resource__c instead of Resources__c. This will solve your problem.

There are lot of materials available for understanding SOQL. I would start with "Working with Data in Apex" from the Apex Developer Guide to understand basics, but the below link is also useful.

http://www.salesforce.com/us/developer/docs/soql_sosl/index.htm


Thanks,
Shailesh.