Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
public with sharing class contollertest {

    Public id Current_le_Id;

    public Boolean isEdit { set; get;}

    public List<Question__c> lstQuestion {set;get;}

    public contollertest (ApexPages.StandardController controller) {

        Current_le_Id = controller.getRecord().id;

        isEdit = false;

        lstQuestion = New List<Question__c>();

        for(Lead le:[select id,name,(select id,Name,Email__c from Questions__r) from lead where id=:Current_le_Id]){

           for(Question__c con:le.Question__c)

               lstQuestion.add(con);

        }

    }

    public void editProcess(){

        isEdit = true;

    }

    public  void save(){

        

        if(lstQuestion.size() > 0){

            upsert lstQuestion;

            lstQuestion.clear();

        }

        

        for(Lead le:[select id,name,(select id,Name,Email__c from Questions__r) from lead where id=:Current_le_Id]){

           for(Question__c con:le.Question__c)

               lstQuestion.add(con);

        }

        isEdit = false;

    }

    public void addQuestion(){

        lstQuestion.add(new Question(leadId = Current_le_Id));

        isEdit = true;

    }

}

<!--Page-->

<apex:page standardController="Account" extensions="contrllr">

  <apex:form >

    <apex:pageblock id="pgb">

    <apex:pageBlockButtons >

        <apex:commandButton value="edit" action="{!editProcess}" rendered="{!Not(isEdit)}" reRender="pgb"/>

        <apex:commandButton value="save" action="{!save}" rendered="{!isEdit}" reRender="pgb"/>        

        </apex:pageBlockButtons>

       <apex:pageBlockTable value="{!lstQuestion}" var="val" rendered="{!Not(isEdit)}">

         <apex:column value="{!val.Name}"/>

         <apex:column value="{!val.Email__c}"/>

       </apex:pageBlockTable> 

       <apex:outputPanel rendered="{!Not(isEdit)}">

           <apex:commandButton action="{!addQuestion}" value="Add Contact" reRender="pgb"/>

       </apex:outputPanel>

        <apex:pageBlockTable value="{!lstQuestion}" var="val" rendered="{!(isEdit)}">

         <apex:column headerValue="FirstName">

             <apex:inputField value="{!val.Name}"/>

         </apex:column>

          <apex:column headerValue="Email">

             <apex:inputField value="{!val.Email__c}"/>

         </apex:column>

         <apex:column >

             <apex:inputField value="{!val.Email__c}"/>

         </apex:column>

       </apex:pageBlockTable> 

    </apex:pageblock>

  </apex:form>

</apex:page>
13 answers
  1. May 12, 2016, 12:34 PM

    Hi Sumit,

    This is Quite confusing.

    First of all I would like to tell you that, You can not Use ID as you have written above. It means you are trying to reference id of Question__c type record but your ID value is of a lead  type record (they always starts with 00Q). Hence it is giving you invalid ID value Error.

    Now for the other issue. Please go to the fields page of Question__c. Check The API name Of  LeadID. use that name as apiname=Current_lead_Id. 

    this will solve all the issues I guess. Or please share a snapshot of fields of Question__c.

    I will be happy to help.

    Regards

    Abhilash Mishra
Loading
0/9000