• sfelf
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I have a PersonAccount Student which has a Detail custom Object Date, which is a list of the date the student entered and left. I create the student and insert it no problem. But when I try to add the student id which is the Master to the Date's student field and insert, I get the following DML Exception error:


System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Student: id value of incorrect type: 001T000000h4YlVIAU: [Student__c]

 

Here is the controller:

public with sharing class studentApplicationController {

    // Non-Object VF Fields
    public String lastname { get; set; }
    public String firstName { get; set; }
    public String salutation { get; set; }

    // Object Variable
    Account student;
    Date__c startdate;
    RelativeContact__c spouse;
    RelativeContact__c father;
    RelativeContact__c mother;
    List<Educational_Institution__c> schools;
    
    // Other Variables
    String submittedPageURL = '';
    
    // util methods
    RecordType getPersonAccountRecordTypeId() {
        return [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
    }
    
    // Getters
    public Account getStudent() {
        if(student == null) {
            RecordType recType = getPersonAccountRecordTypeId();            
            student = new Account(recordtypeid=recType.id);
            //student = new Account();
        }
        return student;
    }
 
   
    public Date__c getStartDate() {
        if(startdate == null) {
            startdate = new Date__c(status__c='Entered - Non-Academic');
        }    
        return startdate;
    }   
     
    
    // Save the application into Salesforce
    public PageReference save() {
        
        student.lastname = lastname;
        student.firstname = firstname;
        student.salutation = salutation;
        insert student;
        
        System.debug('Student Id is: '+student.id);
        startdate.student__c = student.id;
        insert startdate;
        
        PageReference submittedPage = new PageReference(submittedPageURL);
        submittedPage.setRedirect(true);
        return submittedPage;
    }
}

 

 

According to the debug, the student does have a valid id, so it's not a null value issue.

 

Here is the test code:

 

 

@isTest
private class StudentApplicationControllerTest {

    static testMethod void testController() {
        studentApplicationController sac = new StudentApplicationController();
        sac.getStudent();
        sac.firstName = 'Unit';
        sac.lastname = 'Test';
        sac.salutation = 'Mr.';
        
        sac.getStartDate().Date__c = Date.newInstance(2, 25, 2011);
        
        sac.save();
    }
}

 

 

 

I get the same error when trying from my VF page.

 

I am not using queues. But the Account is a person account.

 

Any help would be greatly appreciated.

  • February 25, 2011
  • Like
  • 0

Install Excel Connector XLA

The sforce_connect.xla is an Excel Add-In and not intended to be opened directly by clicking on the XLA file. To Install the XLA file into Excel:
  1. Launch Excel
  2. Click on the Tools menu bar
  3. Click on -> Add-Ins...
  4. Click on the Browse button, locate the Add-In file from the directory where you unpacked the ZIP file
  5. select the add-in and click OK to load it.
It says that click on Tools menu bar,I have office 2007 but I do not see tools menu bar.Guys ,how do I get Tools menu Bar in office 2007.Please help
Thanks,
Trick