1

I have custom object called offering_details__C which lookup to question .

visualforce page for question with saved in the custom object and list all the question in the same page . Below is the code. am facing problem with zone in the question .. How to get id of the custom object in the visualforce.

<apex:page showHeader="true" sidebar="true" standardController="question" extensions="iNeedChatterAnswers">
<apex:form >
<apex:pageBlock title="Question information" mode="edit" >
<apex:pageBlockButtons >
            <apex:commandButton action="{!saveMethod}" value="Save"/>
            <apex:commandButton action="{!Cancel}" value="Cancel"/>
            <apex:commandButton Id="btnSearch" action="{!search}" rerender="renderBlock" status="status" title="Search" value="Search"/>
            </apex:pageBlockButtons>

<apex:pageBlockSection title="Question page" columns="2">
                 <apex:inputtext id="searchTextBox" value="{!searchText}"/>
                 <apex:inputField value="{!questionData.Title}"/><br/>
                 <apex:inputField value="{!questionData.Body}"/>
                 <!--<apex:inputField value="{!questionData.Community}"/-->
                 </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller code:

public with sharing class iNeedChatterAnswers {
    Public Question questionData {get;set;}
    public Offering_Details__c offeringData {get;set;}
    Id offeringId;
    public iNeedChatterAnswers(ApexPages.StandardController controller) {
        Id offeringId = ApexPages.CurrentPage().getParameters().get('id');
        if(offeringId == null)
            offeringId = 'a1HS0000001dCMM';

        questionData = (Question)controller.getRecord();

       // offeringData =[]
    }

    public PageReference saveMethod (){

        questionData.Question_title__c  = offeringId;
        questionData.CommunityId ='09aS0000000CdTuIAK';
        insert questionData;

        return null;
        //PageReference myPage = Page.

    }
}

1 Answer 1

1

You can simply access it just like any other variable. I'm assuming that since you have a list of your custom items you would put it in some sort of repeat or pageBlockTable.

<apex:repeat value="{!offeringData}" var="data">
  <apex:outputField value="{!data.Id}" /><br/>
</<apex:repeat>

EDIT: Since your custom object looks up to Question, you need to actually have a list of your custom object and not just a single one.

public Offering_Details__c offeringData {get;set;} -> public List<Offering_Details__c> offeringData {get;set;}

EDIT 2:

//I don't know the actually lookup field since you didn't give this information but you should be able to figure it out.
offeringData = [SELECT Id FROM Offering_Details__c WHERE QuestionId = :offeringId];
3
  • Thanks .. how can i get the list of question in the same visualforce page..and having search input field in the page to search questions.
    – satish
    Commented Sep 5, 2014 at 9:45
  • 1
    You have the Id of the parent, and so query for all the children with it.
    – dphil
    Commented Sep 5, 2014 at 13:41
  • Am trying do it but am not getting and how to search frm question list .. can u guide me.
    – satish
    Commented Sep 6, 2014 at 16:10

You must log in to answer this question.

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