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
JPSeaburyJPSeabury 

Simple Apex record update is throwing a DML error

I must be overlooking something very basic, but I don't understand why this code is throwing a DmlException error when I evoke the update.

 

I've stripped the code down to bare basics, hoping the problem would jump out at me - but it isn't.

 

public class FacultyApprovalWizard { private final Account thisStudent; public FacultyApprovalWizard() { thisStudent = [select Id, Name, Department_Notified_GPA__c, X2TOR_Recommendation__c, UNIV_Response_Due__c from Account where id = :System.currentPageReference().getParameters().get('id')]; } public Account getThisStudent() { return thisStudent; } public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } public PageReference saveAttachments() { // Add the attachment to our Person-Account(Student) record attachment.parentid = thisStudent.id; insert attachment; // redraw the page, so user can see their Attachment has been added to Student record PageReference page = ApexPages.currentPage(); page.setRedirect(true); return page; } public PageReference step1() { return Page.RequestFacultyApproval1; } public PageReference step2() { update thisStudent; return null; // return Page.RequestFacultyApproval2; } public PageReference cancel() { PageReference accountPage = new PageReference('/' + thisStudent.id); accountPage.setRedirect(true); return accountPage; } }

 

 

As soon as I hit the Update highlighted, I get this error.

 

 

System.DmlException: Update failed. First exception on row 0 with id 001Q0000002NXtJIAW;

first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on

insert/update call: Name: [Name]

 

Class.FacultyApprovalWizard.step2: line 39, column 7
External entry point

 

 

If it's releveant, these are Person-Account fields (not regular Account fields). Here's the VF page (though I think the problem is in my Apex class):

 

 

<apex:page controller="FacultyApprovalWizard" tabStyle="Account"> <!-- ABSTRACT: Evoked from button on Applied Student Person-Account record type --> <!-- Navigates user through the step of sending Faculty Approval Request and Attachments. --> <!-- TEMP SID: 001Q0000002IwlC --> <apex:sectionHeader title="Submit for Faculty Approval Wizard" subtitle="Step 1: Select Attachments" /> <apex:form > <apex:pageBlock title="Student Information" mode="edit"> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!step2}" value="Step 2: Select Faculty Reviewers" /> <apex:commandButton action="{!cancel}" value="Cancel" /> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:outputField value="{!thisStudent.Name}"/> <apex:inputField value="{!thisStudent.Department_Notified_GPA__c}" required="TRUE"/> <apex:inputField value="{!thisStudent.X2TOR_Recommendation__c}" required="TRUE"/> <br/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Select Attachments"> <apex:pageBlockSection > <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/> <apex:commandButton value="save" action="{!saveAttachments}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:relatedList list="NotesAndAttachments" subject="{!thisStudent}"/> </apex:page>

 

I did some stare and compare at this document article, but it looks like we're largely doing similar things.

Message Edited by JPSeabury on 04-21-2009 07:10 PM
Best Answer chosen by Admin (Salesforce Developers) 
JPSeaburyJPSeabury

Simon gave me the answer on Twitter, posting here for the benefit of the community:

 

 

Twitter to the Rescue (again)

 

 

I had a hunch this might be the case, but I was trying to talk myself out of it.  =)

All Answers

JPSeaburyJPSeabury

Simon gave me the answer on Twitter, posting here for the benefit of the community:

 

 

Twitter to the Rescue (again)

 

 

I had a hunch this might be the case, but I was trying to talk myself out of it.  =)

This was selected as the best answer
AneskeAneske

Thanks for the tip - certainly helped me. my error was : first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Name: [Name}, So I just removed the Name Field from my list ==== Thanks

carmantcarmant

Thanks for this - had me stumped for a few minutes!!