So, the relevant snippets of code are:
function doFunction(choice) { switch (choice) { case "changename": changeName(document.getElementById("makeNewName").value); break; } }
<apex:form >
<apex:pageBlock mode="edit" title="Clone Job" >
<apex:actionFunction name="changeName" action="{!saveCloneObjects}">
<apex:param name="newName" value="" />
</apex:actionFunction>
<apex:pageBlockButtons >
<button type="button" onclick="doFunction('changename');" id="saveButton" value="Clone Job">Clone Job</button>
<!--<apex:commandButton action="doFunction('changename');" id="saveButton" value="Clone Job" />-->
<apex:commandButton action="{!cancel}" id="cancelButton" value="Cancel" style="float:right;" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Insert New Job Title" columns="3">
<input type="text" value="insert new job name" onFocus="this.value=''" id="makeNewName"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</html>
public jobCloneClass(ApexPages.StandardController stdController){
j = (Job__c)stdController.getRecord();
}
...
...
...
clonedJob = (Job__c)clonedSObjects[0];
String newName = Apexpages.currentPage().getParameters().get('newName');
clonedJob.Name = null;
clonedJob.Name = newName;
...
...
...
upsert clonedJob;
PageReference jobPage = new PageReference('/' + clonedJob.id);
jobPage.setRedirect(true);
return jobPage;
where clonedJob was made by using sObject.clone() on the existing record, and all fields were selected in the relevant query.
Now, when I click the "clone job" button, a new record is indeed created, but instead of the cloned record updating it's name to be the string living in the text box id="makeNewName", the new record instead updates it's name to be it's ID.
I cannot figure out for the life of me why this is happening... does anyone have any insight?
public String newName{get; set;}to the controller and use<apex:param name="newName" assignTo="{!newName}" value="" />on the page. (and take out the Apexpages line in controller) – zjeh Jan 25 at 21:53