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

Unable to save data into related list table
Hi Guys,
Good day!
I was able to get our web form loaded into the following Sites domain but still having issues with saving data into a related list table.
Site domain:
http://vitallogistics.vl.cs9.force.com/billoflading
Apex class extension:
public class BillofLadingtest1Extension { private ApexPages.StandardController std; // the associated contacts public List<Skid__c> skids; // the chosen contact id - used when deleting a contact public Id chosenskidId {get; set;} public String newSkidName {get; set;} public String newSkidDimension {get; set;} public Decimal newSkidNumberofPieces {get; set;} public BillofLadingtest1Extension() { } public BillofLadingtest1Extension(ApexPages.StandardController stdCtrl) { std=stdCtrl; } public Bill_of_Lading__c getBillofLading() { return (Bill_of_Lading__c) std.getRecord(); } public SObject getSobject() { return std.getRecord(); } private boolean updateSkids() { boolean result=true; if (null!=skids) { // TODO: should work out what's changed and then save, easier to update everything for prototype List<Skid__c> updSkids=new List<Skid__c>(); try { update skids; } catch (Exception e) { String msg=e.getMessage(); integer pos; // if its field validation, this will be added to the messages by default if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, '))) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg)); } result=false; } } return result; } public PageReference saveAndExit() { boolean result=true; result=updateSkids(); if (result) { // call standard controller save return std.save(); } else { return null; } } public PageReference save() { Boolean result=true; PageReference pr=Page.BillofLadingtest; if (null!=getBillofLading().id) { result=updateSkids(); } else { pr.setRedirect(true); } if (result) { // call standard controller save, but don't capture the return value which will redirect to view page std.save(); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved')); } pr.getParameters().put('id', getBillofLading().id); return pr; } public void newSkid() { if (updateSkids()) { Skid__c skid=new Skid__c(Name=newSkidName, Dimension__c=newSkidDimension, Number_of_Pieces__c=newSkidNumberofPieces, Bill_of_Lading__c=getBillofLading().id); insert skid; newSkidName=null; newSkidDimension=null; newSkidNumberofPieces=null; skids=null; } } public void deleteSkid() { if (updateSkids()) { if (null!=chosenskidId) { Skid__c skid=new Skid__c(Id=chosenskidId); delete skid; skids=null; chosenskidId=null; } } } public List<Skid__c> getSkids() { if ( (null!=getBillofLading().id) && (skids == null) ) { skids=[SELECT Id, Name, Bill_of_Lading__c, Dimension__c, Number_of_Pieces__c, UOM__c, Weight__c FROM Skid__c WHERE Id =: getBillofLading().id ORDER BY CreatedDate]; } return skids; } }
Reference VF page code:
<apex:outputPanel id="contactList"> <apex:repeat value="{!contacts}" var="contact" > <apex:pageBlockSection columns="1" title="Contact {!contact.Name}" collapsible="true"> <apex:pageBlockSectionItem > <apex:pageBlockSection columns="2"> <apex:inputField value="{!Contact.FirstName}" styleClass="form_field"/> <apex:inputField value="{!Contact.LastName}" styleClass="form_field"/> <apex:inputField value="{!Contact.HomePhone}" styleClass="form_field"/> </apex:pageBlockSection> </apex:pageBlockSectionItem> </apex:pageBlockSection> <div style="text-align:center"> <apex:commandButton value="Delete This Contact" onclick="idToDelete='{!contact.id}'; showpopup('deletecontent'); return false;"/> </div> </apex:repeat> </apex:outputPanel>
Replicated using this, which is giving an error when an input field is entered under the skid object:
<apex:outputPanel id="skidList"> <apex:repeat value="{!skids}" var="skid" > <apex:pageBlockSection columns="1" title="Skid {!skid.Name}" collapsible="true"> <apex:pageBlockSectionItem > <apex:pageBlockSection columns="2"> </apex:pageBlockSection> </apex:pageBlockSectionItem> </apex:pageBlockSection> <div style="text-align:center"> <apex:commandButton value="Delete This Skid" onclick="idToDelete='{!skid.id}'; showpopup('deletecontent'); return false;"/> </div> </apex:repeat> </apex:outputPanel>
Unable to save into something like this (Account with contact records in the same visualforce page):
http://screencast.com/t/6mstiuF5mmYJ
Any help would be appreciated.
Regards,
Phil Dennison C. Fang
Salesforce Developer