You need to sign in to do that
Don't have an account?
SFDC 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)
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 :)
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 :)
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. 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:
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.
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.