You need to sign in to do that
Don't have an account?
Sangeet kasera
how to update particular row data in PageBlock Table using inline editing in Visualforce Page?
I am not good In Visualforce Page, Please help me out...
I have created one vf page for searching user record stored in custom object Subscription__c by from which user directly subscribe or unsubscribe the record using command button.
I also added one more button for inline editing, but for that editing is working fine, I am able to do so but the record is not getting updated now means it is not getting saved.
UI:-
Apex Class :-
public with sharing class ListPageForAdminController {
public boolean hideSec{get; set;}
public List<Subscription__c> subsD {get;set;}
public String searchKey {get;set;}
public Id paramValue3 {get;set;}
public integer totalRecs = 0;
public integer OffsetSize = 0;
public integer LimitSize= 5;
public ListPageForAdminController(){
hideSec = false;
totalRecs = [select count() from Subscription__c];
}
public pagereference perform(){
subsD = new List<Subscription__c>();
List<String> searchData = new List<String>();
searchData = searchKey.split(',');
string searchquery='SELECT id, SubscribedBy__c, ObjectSubscription__c,Record_Id__c,Activated__c FROM Subscription__c';
string whereClause = ' where ';
if(searchKey == ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter UserDetail'));
if(subsD.isEmpty()){
subsD.clear();
hideSec = false;
}
}
else{
for (string s : searchData){
if (whereClause == ' where '){
whereClause += ' SubscribedBy__r.Name like \'%'+ s +'%\' OR SubscribedBy__r.Email like \'%'+ s +'%\' ';
}
else{
whereClause += ' or SubscribedBy__r.Name like \'%'+ s +'%\' OR SubscribedBy__r.Email like \'%'+s+'%\' ';
}
}
hideSec = true;
searchquery += whereClause + ' LIMIT :LimitSize OFFSET :OffsetSize' ;
subsD= Database.query(searchquery);
}
return null;
}
public PageReference quickUpdat(){
try{
List<Subscription__c> obj1 = new List<Subscription__c>();
Subscription__c initial11 = new Subscription__c();
initial11.Id = paramValue3;
obj1.add(initial11);
update obj1;
return ApexPages.CurrentPage();
}
catch(Exception e) {
System.debug('@@@Error');
return null;
}
}
public PageReference SubORUnSub(){
List<Subscription__c> obj1 = new List<Subscription__c>();
Subscription__c initial = new Subscription__c();
initial.id = paramValue3;
if(paramValue4==false){
initial.Activated__c = true;
}
else {
initial.Activated__c = false;
}
obj1.add(initial);
update obj1;
System.debug('alt' + paramValue3);
System.debug('alt' + paramValue4);
return null;
}
}
Visualforce Page:-
<apex:page title="List Page For Admin" controller="ListPageForAdminController" lightningStylesheets="true" sidebar="false" id="thePage">
<style>
</style>
<script>
function decimalOnly(e){
e.value = e.value.replace(/[^A-Za-z\,@.]/g,'');
if(e.value.split(',').length>2) e.value = e.value.replace(/ \,+$/,"");
};
</script>
<apex:slds />
<div>
<div class="slds-scope">
<apex:form >
<div class="slds-grid slds-wrap">
<div class="slds-col slds-size_12-of-12">
<div class="slds-grid slds-wrap">
<div class="slds-col slds-size_12-of-12">
<div class="slds-col slds-size_5-of-12">
<apex:pageMessages ></apex:pageMessages>
</div>
<span class="searchBox_Label">Enter UserDetail to Search</span>
<apex:inputText value="{!searchKey}" html-placeholder="Enter Text to search" onkeyup="decimalOnly(this);" label="Input" style="width: 300px;line-height: 2;margin-left: 10px;"/>
<apex:commandButton value="Search records" action="{!perform}" styleClass="slds-button slds-button--brand" style="width: 153px;border-radius: 17px;line-height: 2;margin-left: 10px;"/>
</div>
<div class="slds-col slds-size_12-of-12" id="op" >
<apex:pageBlock title="Search Result" id="details" rendered="{!hideSec}" mode="inlineEdit">
<apex:pageBlockTable value="{!subsD}" var="srh">
<apex:column value="{!srh.id}"/>
<apex:column value="{!srh.ObjectSubscription__c}"/>
<apex:column value="{!srh.Record_Id__c}"/>
<apex:column value="{!srh.Activated__c}"/>
<apex:column value="{!srh.SubscribedBy__c}"/>
<apex:column >
<apex:commandButton id="update" action="{!quickUpdat}" value="save" >
<apex:param name="subId" value="{!srh.id}" assignTo="{!paramValue3}"/>
</apex:commandButton>
</apex:column>
<apex:column title="Action" headerValue="Subscribe/Unsubscribe">
<apex:commandButton value="{!if(srh.Activated__c = true,'UnSubscribe', 'Subscribe')}" action="{!SubORUnSub}" oncomplete="window.location.reload();" styleClass="{!if(srh.Activated__c = true,'slds-button slds-button--destructive', 'slds-button slds-button--success')}" style="width: 192px;border-radius: 17px;line-height: 2;margin-left: 10px;">
<apex:param name="subscriptionId" value="{!srh.id}" assignTo="{!paramValue3}"/>
<apex:param name="subsActivated" value="{!srh.Activated__c}" assignTo="{!paramValue4}"/>
</apex:commandButton>
</apex:column>
<apex:inlineEditSupport showOnEdit="update, cancelButton" hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit">
</apex:inlineEditSupport>
</apex:pageBlockTable>
<apex:pageblockButtons >
<apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
</apex:pageBlock>
</div>
</div>
</div>
</div>
</apex:form>
</div>
</div>
</apex:page>
I have created one vf page for searching user record stored in custom object Subscription__c by from which user directly subscribe or unsubscribe the record using command button.
I also added one more button for inline editing, but for that editing is working fine, I am able to do so but the record is not getting updated now means it is not getting saved.
UI:-
Apex Class :-
public with sharing class ListPageForAdminController {
public boolean hideSec{get; set;}
public List<Subscription__c> subsD {get;set;}
public String searchKey {get;set;}
public Id paramValue3 {get;set;}
public integer totalRecs = 0;
public integer OffsetSize = 0;
public integer LimitSize= 5;
public ListPageForAdminController(){
hideSec = false;
totalRecs = [select count() from Subscription__c];
}
public pagereference perform(){
subsD = new List<Subscription__c>();
List<String> searchData = new List<String>();
searchData = searchKey.split(',');
string searchquery='SELECT id, SubscribedBy__c, ObjectSubscription__c,Record_Id__c,Activated__c FROM Subscription__c';
string whereClause = ' where ';
if(searchKey == ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter UserDetail'));
if(subsD.isEmpty()){
subsD.clear();
hideSec = false;
}
}
else{
for (string s : searchData){
if (whereClause == ' where '){
whereClause += ' SubscribedBy__r.Name like \'%'+ s +'%\' OR SubscribedBy__r.Email like \'%'+ s +'%\' ';
}
else{
whereClause += ' or SubscribedBy__r.Name like \'%'+ s +'%\' OR SubscribedBy__r.Email like \'%'+s+'%\' ';
}
}
hideSec = true;
searchquery += whereClause + ' LIMIT :LimitSize OFFSET :OffsetSize' ;
subsD= Database.query(searchquery);
}
return null;
}
public PageReference quickUpdat(){
try{
List<Subscription__c> obj1 = new List<Subscription__c>();
Subscription__c initial11 = new Subscription__c();
initial11.Id = paramValue3;
obj1.add(initial11);
update obj1;
return ApexPages.CurrentPage();
}
catch(Exception e) {
System.debug('@@@Error');
return null;
}
}
public PageReference SubORUnSub(){
List<Subscription__c> obj1 = new List<Subscription__c>();
Subscription__c initial = new Subscription__c();
initial.id = paramValue3;
if(paramValue4==false){
initial.Activated__c = true;
}
else {
initial.Activated__c = false;
}
obj1.add(initial);
update obj1;
System.debug('alt' + paramValue3);
System.debug('alt' + paramValue4);
return null;
}
}
Visualforce Page:-
<apex:page title="List Page For Admin" controller="ListPageForAdminController" lightningStylesheets="true" sidebar="false" id="thePage">
<style>
</style>
<script>
function decimalOnly(e){
e.value = e.value.replace(/[^A-Za-z\,@.]/g,'');
if(e.value.split(',').length>2) e.value = e.value.replace(/ \,+$/,"");
};
</script>
<apex:slds />
<div>
<div class="slds-scope">
<apex:form >
<div class="slds-grid slds-wrap">
<div class="slds-col slds-size_12-of-12">
<div class="slds-grid slds-wrap">
<div class="slds-col slds-size_12-of-12">
<div class="slds-col slds-size_5-of-12">
<apex:pageMessages ></apex:pageMessages>
</div>
<span class="searchBox_Label">Enter UserDetail to Search</span>
<apex:inputText value="{!searchKey}" html-placeholder="Enter Text to search" onkeyup="decimalOnly(this);" label="Input" style="width: 300px;line-height: 2;margin-left: 10px;"/>
<apex:commandButton value="Search records" action="{!perform}" styleClass="slds-button slds-button--brand" style="width: 153px;border-radius: 17px;line-height: 2;margin-left: 10px;"/>
</div>
<div class="slds-col slds-size_12-of-12" id="op" >
<apex:pageBlock title="Search Result" id="details" rendered="{!hideSec}" mode="inlineEdit">
<apex:pageBlockTable value="{!subsD}" var="srh">
<apex:column value="{!srh.id}"/>
<apex:column value="{!srh.ObjectSubscription__c}"/>
<apex:column value="{!srh.Record_Id__c}"/>
<apex:column value="{!srh.Activated__c}"/>
<apex:column value="{!srh.SubscribedBy__c}"/>
<apex:column >
<apex:commandButton id="update" action="{!quickUpdat}" value="save" >
<apex:param name="subId" value="{!srh.id}" assignTo="{!paramValue3}"/>
</apex:commandButton>
</apex:column>
<apex:column title="Action" headerValue="Subscribe/Unsubscribe">
<apex:commandButton value="{!if(srh.Activated__c = true,'UnSubscribe', 'Subscribe')}" action="{!SubORUnSub}" oncomplete="window.location.reload();" styleClass="{!if(srh.Activated__c = true,'slds-button slds-button--destructive', 'slds-button slds-button--success')}" style="width: 192px;border-radius: 17px;line-height: 2;margin-left: 10px;">
<apex:param name="subscriptionId" value="{!srh.id}" assignTo="{!paramValue3}"/>
<apex:param name="subsActivated" value="{!srh.Activated__c}" assignTo="{!paramValue4}"/>
</apex:commandButton>
</apex:column>
<apex:inlineEditSupport showOnEdit="update, cancelButton" hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit">
</apex:inlineEditSupport>
</apex:pageBlockTable>
<apex:pageblockButtons >
<apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
</apex:pageBlock>
</div>
</div>
</div>
</div>
</apex:form>
</div>
</div>
</apex:page>
I refered through below page for custom table <apex:actionRegion> for inline edit and it work fine for me.
https://developer.salesforce.com/forums/?id=906F000000097nvIAA
I Made changes in my Visualforce page also in Class then it worked.
Regards,
Sangeet
All Answers
As mentioned in the developer documentation https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inlineEditSupport.htm can you try it with apex:outputField tag and check if this works?
Looking forward for your response.
Regards,
Anutej
My Inline editing is working fine but i am not able to save the record on object after editing may be there is a issue in my function [ quickUpdat ]
Will you please look into this.
And as per developer guide when I am using output panel for inline editing then there is a error coming on
Line 0 it says - ListPageForAdminController .save() is not exist (Same with edit and cancel button both).
I am using custom controller somay be standard save, edit and cancel button is not supportable...
Regards,
Sangeet
I refered through below page for custom table <apex:actionRegion> for inline edit and it work fine for me.
https://developer.salesforce.com/forums/?id=906F000000097nvIAA
I Made changes in my Visualforce page also in Class then it worked.
Regards,
Sangeet