You need to sign in to do that
Don't have an account?
MaggieSumit
How add edit field option on these code?
<apex:page standardController="Account" extensions="contrller">
<apex:form >
<apex:pageblock >
<!-- Display Account related Contacts -->
<apex:pageBlockTable value="{!relatedContacts}" var="val">
<apex:column value="{!val.name}"/>
<apex:column value="{!val.email}" />
<apex:inputField value="{!val.name}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
public with sharing class contrller {
Public id Current_Acc_Id;
public contrller(ApexPages.StandardController controller) {
Current_Acc_Id = controller.getRecord().id;
}
public List<Contact> getrelatedContacts(){
List <contact> conList = New List<Contact>();
for(Account acc:[select id,name,(select name,id,email from contacts) from account where id=:Current_Acc_Id]){
for(contact con:acc.contacts)
conList.add(con);
}
return conList;
}
}
<apex:form >
<apex:pageblock >
<!-- Display Account related Contacts -->
<apex:pageBlockTable value="{!relatedContacts}" var="val">
<apex:column value="{!val.name}"/>
<apex:column value="{!val.email}" />
<apex:inputField value="{!val.name}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
public with sharing class contrller {
Public id Current_Acc_Id;
public contrller(ApexPages.StandardController controller) {
Current_Acc_Id = controller.getRecord().id;
}
public List<Contact> getrelatedContacts(){
List <contact> conList = New List<Contact>();
for(Account acc:[select id,name,(select name,id,email from contacts) from account where id=:Current_Acc_Id]){
for(contact con:acc.contacts)
conList.add(con);
}
return conList;
}
}
For New functionality update your code with below page and Controller code
Thanks.
All Answers
You are using the name field in input field this field can't be as input because this field is composite type.So on edit you need to use the firstName and lastName field as inputField.
And for better understanding i am posting the sample code with edit and save button which can be useful for you
If this post solves your problem kindly mark it as solution.
Thanks
example :
(Account acc:[select id,name,(select lastName,firstName,name,id,email from contacts) from account where id=:Current_Acc_Id]
For New functionality update your code with below page and Controller code
Thanks.
Lead and Question__c i have these two object. Question__c related with Lead, If use for this code where i need to change.
Public id Current_Lead_Id;
public Boolean isEdit { set; get;}
public List<Question__c> lstContact {set;get;}
public contollertest (ApexPages.StandardController controller) {
Current_Lead_Id = controller.getRecord().id;
isEdit = false;
lstContact = New List<Question__c>();
for(Lead Lead:[select id,name,(select id,Questions__r.Name from Question__c) from Lead where id=:Current_Lead_Id]){
for(Question__c con:acc.contacts)
lstContact.add(con);
}
}
geeting this error message: Didn't understand relationship 'Question__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Lead Lead:[select id,name,(select id,Name from Questions__r) from Lead where id=:Current_Lead_Id
My Code: Please review my code
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,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,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;
}
}