function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Oron MizrachiOron Mizrachi 

Inline edit query result from costume object visualforce

the Inline Editing doesn't work in the pageBlockTable (editable but doesn't update changes).

my suspicions its related to the need to update controller object from sql query running on costume object.

buy i don't know how to solve it , because its the best method to get this specific data. Any ideas?

Thank you.

Visualforce Page
<apex:page showHeader="false" sidebar="false" standardController="ACCOUNT"  extensions="BackStationsController">
 <apex:form >

 <apex:pageBlock title="Room Deatels" >

<apex:pageBlockButtons location="bottom">

   <apex:commandButton action="{!save}" id="saveButton" value="Save" rendered="true"/>
  </apex:pageBlockButtons>
  <apex:pageMessages /> 

  <apex:pageBlockSection columns="1"  title="Room Guests List" rendered="TRUE" collapsible="false">

    <apex:pageBlockTable value="{!constroom}" var="croom"  rows="5">
     <apex:inlineEditSupport event="ondblclick"   changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/> 


       <apex:column headerValue="Local ID" value="{!croom.PasiveAccount__r.Local_ID__c}"/>
      <apex:column headerValue="First Name" value="{!croom.PasiveAccount__r.firstname}"/>
      <apex:column headerValue="Last Name" value="{!croom.PasiveAccount__r.lastname}"/>
      <apex:column headerValue="Email" value="{!croom.PasiveAccount__r.PersonEmail}"/>
       <apex:column headerValue="Phone" value="{!croom.PasiveAccount__r.phone}"/>


    </apex:pageBlockTable>
  </apex:pageBlockSection>

     </apex:outputPanel>
             </apex:pageBlock>


</apex:form>

Extension
public with sharing class BackStationsController {



  public BackStationsController(ApexPages.StandardController std) {
     stdCtrl=std;
     integer  Tempcount = [Select Count() from UnitCloneJunc__c where ActiveAccount__r.id =:stdCtrl.getId()];
     if (stdCtrl.getId() != NULL && temp >0 )
        setupRoomchange();
}


private ApexPages.StandardController stdCtrl {get; set;}
public List<UnitCloneJunc__c> constroom {get; set;} 


Private void setupRoomchange(){
   constroom=[select  ID,PasiveAccount__r.phone, PasiveAccount__r.firstname, PasiveAccount__r.lastname,PasiveAccount__r.PersonEmail,PasiveAccount__r.Local_ID__c from UnitCloneJunc__c where id != null and ActiveAccount__r.isPersonAccount = true and ActiveAccount__r.id =:stdCtrl.getId() order by CreatedDate ASC];
  }

 
Alexander TsitsuraAlexander Tsitsura
Hi Oron,

Uou call save method from standart controller, this save only account record for which you open page. You need write own save method, and don't forgot that when you update UnitCloneJunc__c it's not updated related PasiveAccount__r record.
 
public PageReference saveConstRoom() {
     Account[] accountsToUpdate = new Account[] {};
     for (UnitCloneJunc__c u : constroom) {  
         accountsToUpdate.add(u.PasiveAccount__r);
     }

     update accountsToUpdate;
     return null; // or some record id
}

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
Oron MizrachiOron Mizrachi
Hi alexander, thank you.
though it dosent work. 
constroom sql return multiple PasiveAccount__r, how would it knows to update the spacific PasiveAccount__r been edited? 
im using in a in a diffrenete table (but similar use) a commandlink ('delete guest') and <apex:param name="selAccId" value="{!croom.Id}" assignTo="{!selectedelId}" /> to pass the selected Account id parameter . but i dont know how to do it with Inline edit.
Alexander TsitsuraAlexander Tsitsura
Hi Oron,

As i understand, u want edit some "PasiveAccount__r" fields and save only records that contains changes.

For it u can create duplicate(full copy) - old version of initial constroom array, user edit only original constroom and when click save button u need check both array for determine changes.

Please see code below
 
public with sharing class BackStationsController {



  public BackStationsController(ApexPages.StandardController std) {
     stdCtrl=std;
     integer  Tempcount = [Select Count() from UnitCloneJunc__c where ActiveAccount__r.id =:stdCtrl.getId()];
     if (stdCtrl.getId() != NULL && temp >0 )
        setupRoomchange();
}


private ApexPages.StandardController stdCtrl {get; set;}
public List<UnitCloneJunc__c> constroom {get; set;} 
private List<UnitCloneJunc__c> constroomOld;

Private void setupRoomchange(){
   constroom=[select  ID,PasiveAccount__r.phone, PasiveAccount__r.firstname, PasiveAccount__r.lastname,PasiveAccount__r.PersonEmail,PasiveAccount__r.Local_ID__c from UnitCloneJunc__c where id != null and ActiveAccount__r.isPersonAccount = true and ActiveAccount__r.id =:stdCtrl.getId() order by CreatedDate ASC];

// clone of constroom array
constroomOld = constroom.deepClone();
  }

public PageReference saveConstRoom() {
     Account[] accountsToUpdate = new Account[] {};
     for (Integer i=0; i<constroom.size(); i++) {
         UnitCloneJunc__c curr = constroom[i];
         UnitCloneJunc__c old = constroomOld[i];

         // check which field is used on vf page for updation.
         if (curr.PasiveAccount__r.Local_ID__c != old.PasiveAccount__r.Local_ID__c ||
             curr.PasiveAccount__r.firstname != old.PasiveAccount__r.firstname ||
             curr.PasiveAccount__r.lastname != old.PasiveAccount__r.lastname ||
             curr.PasiveAccount__r.PersonEmail != old.PasiveAccount__r.PersonEmail ||
             curr.PasiveAccount__r.phone != old.PasiveAccount__r.phone
         ) {
                  accountsToUpdate.add(u.PasiveAccount__r);
         }
     }
 

     if (!accountsToUpdate.isEmpty())  update accountsToUpdate;

     return null; // or some record id
}


Thanks,
Alex
 
Oron MizrachiOron Mizrachi

 understood the logic. thank you. but again it dosent work. with no errors, just dosent update.