You need to sign in to do that
Don't have an account?

Edit multiple Records and update on custom VF page
Is it possible to edit existing multiple records and update records on a custom VF page using force.com site by a guest profile?For the example below,I am displaying existing records but unable to edit the existing records.I also gave read/edit permissions to the guest user.Any help is appreciated.
<apex:pageBlock title="Account Related Contacts" id="pb" > <apex:pageMessages /> <apex:variable var="rowNumber" value="{!0}"/> <apex:pageBlockTable id="thetable" title="Contacts" var="acc" value="{!contactList}"> <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext"> <apex:outputText value="{0}" style="text-align:center;"> <apex:param value="{!rowNumber+1}" /> </apex:outputText> </apex:column> <apex:column headerValue="First Name" > <apex:inputField value="{!acc.FirstName}"/> </apex:column> <apex:column headerValue="Last Name" > <apex:inputField value="{!acc.LastName}"/> </apex:column> <apex:column headerValue="Email" > <apex:inputField value="{!acc.Email}"/> </apex:column> <apex:column headerValue="Phone" > <apex:inputField value="{!acc.Phone}"/> <apex:column headerValue="Action" > <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb"> <apex:param name="rowIndex" value="{!rowNumber}"/> </apex:commandButton> <apex:variable var="rowNumber" value="{!rowNumber+1}"/> </apex:column> </apex:pageBlockTable> <apex:commandButton action="{!addRow}" value="Add Contact" reRender="pb"/> <apex:commandButton value="Cancel" action="{!cancel}"/> <apex:pageBlockButtons > <apex:commandButton value="SaveContact" action="{!saveContact}" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form>
public class RelatedContacts{
public Account accounts;
public Contact del; public List < Contact > addContactList {get;set;} public List < Contact > delContactList {get;set;} public List < Contact > contactList {get;set;} public Integer totalCount {get;set;} public Integer rowIndex {get;set;} public List < Contact > delContacts {get;set;} public RelatedContacts(ApexPages.StandardController controller) { accounts = (Account) controller.getRecord(); contactList = [Select id, firstName, LastName from Contact where AccountId = : accounts.Id]; totalCount = contactList.size(); delContactList = new List < Contact > (); delContacts = new List < Contact > (); } public void addRow() { addContactList = new List < Contact > (); contactList.add(new Contact(AccountId = accounts.Id)); } public PageReference save() { upsert contactList; delete delContactList; PageReference pageRef = new PageReference('/apex/addcontactpage'); pageRef.getParameters().put('id',accounts.Id); return pageRef; } public void deleteRow() { rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex')); del = contactList.remove(rowIndex); delContactList.add(del); }
}
<apex:pageBlock title="Account Related Contacts" id="pb" > <apex:pageMessages /> <apex:variable var="rowNumber" value="{!0}"/> <apex:pageBlockTable id="thetable" title="Contacts" var="acc" value="{!contactList}"> <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext"> <apex:outputText value="{0}" style="text-align:center;"> <apex:param value="{!rowNumber+1}" /> </apex:outputText> </apex:column> <apex:column headerValue="First Name" > <apex:inputField value="{!acc.FirstName}"/> </apex:column> <apex:column headerValue="Last Name" > <apex:inputField value="{!acc.LastName}"/> </apex:column> <apex:column headerValue="Email" > <apex:inputField value="{!acc.Email}"/> </apex:column> <apex:column headerValue="Phone" > <apex:inputField value="{!acc.Phone}"/> <apex:column headerValue="Action" > <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb"> <apex:param name="rowIndex" value="{!rowNumber}"/> </apex:commandButton> <apex:variable var="rowNumber" value="{!rowNumber+1}"/> </apex:column> </apex:pageBlockTable> <apex:commandButton action="{!addRow}" value="Add Contact" reRender="pb"/> <apex:commandButton value="Cancel" action="{!cancel}"/> <apex:pageBlockButtons > <apex:commandButton value="SaveContact" action="{!saveContact}" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form>
public class RelatedContacts{
public Account accounts;
public Contact del; public List < Contact > addContactList {get;set;} public List < Contact > delContactList {get;set;} public List < Contact > contactList {get;set;} public Integer totalCount {get;set;} public Integer rowIndex {get;set;} public List < Contact > delContacts {get;set;} public RelatedContacts(ApexPages.StandardController controller) { accounts = (Account) controller.getRecord(); contactList = [Select id, firstName, LastName from Contact where AccountId = : accounts.Id]; totalCount = contactList.size(); delContactList = new List < Contact > (); delContacts = new List < Contact > (); } public void addRow() { addContactList = new List < Contact > (); contactList.add(new Contact(AccountId = accounts.Id)); } public PageReference save() { upsert contactList; delete delContactList; PageReference pageRef = new PageReference('/apex/addcontactpage'); pageRef.getParameters().put('id',accounts.Id); return pageRef; } public void deleteRow() { rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex')); del = contactList.remove(rowIndex); delContactList.add(del); }
}