Visualforce page which generates accounts and contacts. I can edit the record contact field, when I use the save button. It does not save my update to the corresponding record. My debug log outputs the complete list of accounts.
Visualforce:
<apex:page controller="actocons" tabStyle="Account">
<apex:form >
<apex:pageBlock mode="inlineEdit">
<apex:pageBlockButtons >
<apex:commandbutton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:repeat value="{!acct}" var="a">
<apex:pageBlockSection id="section1" title="{!a.name}" onclick="document.getElementById(‘{!$Component.section1}’).childNodes[0].childNodes[0].click();">
<script>twistSection(document.getElementById(“{!$Component.section1}').childNodes[0].childNodes[0]);document.getElementById(“{!$Component.section1}').childNodes[0].style.cssText = “cursor:pointer;' </script>
<apex:outputField value="{!a.Name}"/>
<apex:pageBlockTable value="{!a.Contacts}" var="c" id="j1">
<apex:column value="{!c.id}" />
<apex:column value="{!c.lastname}"/>
<apex:column value="{!c.lastname}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:repeat>
</apex:pageBlock>
<script>
twistSection = (function() {
var cached_function = twistSection;
return function(twisty, sectionId) {
cached_function.apply(this, arguments); // use .apply() to call the original twistSection function provided by Salesforce
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
};
}());
</script>
</apex:form>
</apex:page>
Controller:
public class actocons
{
Private Id accID;
public List<Contact> contactList{get;set;}
public list <contact> myContact {set;get;}
public list<account> acct{set;get;}
public actocons()
{
acct=[select id,name,(select id,lastname from contacts)from account limit 5];
myContact = [SELECT Id, Name FROM Contact WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public PageReference save() {
contactList = new List<Contact>();
accID= ApexPages.currentPage().getParameters().get('acId');
contactList = [SELECT FirstName,LastName,Email,Phone FROM Contact WHERE AccountID = : accID];
system.debug('contactList '+ contactList);
update contactList;
return null;
}
}
(`)
formats code as inline. Formatting code as a block means having at least 4 blank spaces at the start of each line + an empty line above and below the code. The easiest way to do that is to highlight your code block and push the{}
button at the top of the text editor window or press ctrl + k (cmd + k on Apple Macbooks).