• jtres
  • NEWBIE
  • 0 Points
  • Member since 2009

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

Ok so here is the scenario.  We have an application object which contains information about several entities: 3 contacts and 3 custom objects we have called involvements, one associated with each person.  Inside of the involvement object we have a drop down list with several options and depending on the option you have selected different fields are displayed and different validation rules are applied.  I am not sure if that is what is causing me this issue, but anytime I attempt to insert a new application object I get this error being thrown:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger parseStudentApplication caused an unexpected exception, contact your administrator: parseStudentApplication: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Contact]: [Contact]: Class.StudentApplicationParser.Parse: line 182, column 9

 

The following is my trigger:

trigger parseStudentApplication on Application_For_Admission__c(after insert) {
    List<Application_For_Admission__c> studentApps = Trigger.new;
    {
        StudentApplicationParser sap = new StudentApplicationParser();
        sap.Parse(studentApps);
    } 
}

 

Here is the class that process the trigger:

public with sharing class StudentApplicationParser {
    public void Parse(List<Application_For_Admission__c> sas)
    {
        List<Contact> contacts = new List<Contact>();
        List<Account> accounts = new List<Account>();
        List<npe4__Relationship__c> relationships = new List<npe4__Relationship__c>();
        List<Involvement__c> involvements = new List<Involvement__c>();
        List<Semester__c> semesters = new List<Semester__c>();
        List<School__c> schools = new List<School__c>();
        for(Application_For_Admission__c sa : sas)
        {
            Contact student = new Contact();
            Account studentAcct = new Account();
            Contact mother = new Contact();
            Account motherAcct = new Account();
            Contact father = new Contact();
            Account fatherAcct = new Account();
            npe4__Relationship__c relToMother = new npe4__Relationship__c();
            npe4__Relationship__c relToFather = new npe4__Relationship__c();
            Involvement__c studentInvolvement = new Involvement__c();
            Involvement__c motherInvolvement = new Involvement__c();
            Involvement__c fatherInvolvement = new Involvement__c();
            student.FirstName = sa.First_Name__c;
            student.LastName = sa.Last_Name__c;
            student.Birthdate = sa.Birthdate__c;
            student.MailingStreet = sa.Student_Address__c;
            student.MailingCity = sa.City__c;
            student.MailingState = sa.State__c;
            student.MailingPostalCode = sa.Zip__c;
            student.OtherPhone = sa.Phone__c;
            student.npe01__PreferredPhone__c = 'Other';
            student.npe01__HomeEmail__c = sa.Student_Email_Address__c;
            student.npe01__Preferred_Email__c = 'Home';
            System.debug('Set all student fields');
            mother.FirstName = sa.Mother_First_Name__c;
            mother.LastName = sa.Mother_Last_Name__c;
            mother.npe01__HomeEmail__c = sa.Mother_Email_Address__c;
            mother.npe01__Preferred_Email__c = 'Home';
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.OtherPhone = sa.Mothers_Home_Phone__c;
            mother.npe01__PreferredPhone__c = sa.Mother_Preferred_Phone__c;
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.MobilePhone = sa.Mothers_Cell_Phone__c;
            if(sa.Mothers_Address__c == null)
            {   
                mother.MailingStreet = sa.Student_Address__c;
                mother.MailingCity = sa.City__c;
                mother.MailingState = sa.State__c;
                mother.MailingPostalCode = sa.Zip__c;
                System.debug('Set all mother fields with same address as child');
            }
            else
            {
                mother.MailingStreet = sa.Mothers_Address__c;
                mother.MailingCity = sa.Mothers_City__c;
                mother.MailingState = sa.Mothers_State__c;
                mother.MailingPostalCode = sa.Mothers_Zip__c;
                System.debug('Set all mother fields with own address');
            }
            father.FirstName = sa.Father_First_Name__c;
            father.LastName = sa.Father_Last_Name__c;
            father.npe01__HomeEmail__c = sa.Father_Email_Address__c;
            father.npe01__Preferred_Email__c = 'Home';
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.OtherPhone = sa.Fathers_Home_Phone__c;
            father.npe01__PreferredPhone__c = sa.Father_Preferred_Phone__c;
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.MobilePhone = sa.Fathers_Cell_Phone__c;
            if(sa.Fathers_Address__c == null)
            {
                father.MailingStreet = sa.Student_Address__c;
                father.MailingCity = sa.City__c;
                father.MailingState = sa.State__c;
                father.MailingPostalCode = sa.Zip__c;
                System.debug('Set all father fields with same address as child');
            }
            else
            {
                father.MailingStreet = sa.Fathers_Address__c;
                father.MailingCity = sa.Fathers_City__c;
                father.MailingState = sa.Fathers_State__c;
                father.MailingPostalCode = sa.Fathers_Zip__c;    
                System.debug('Set all father fields with own address');         
            }
            relToMother.npe4__Contact__c = student.Id;
            relToMother.npe4__RelatedContact__c = mother.Id;
            relToMother.npe4__Description__c = 'Parent/Child';      
            relToMother.npe4__Status__c = 'Active'; 
            relToMother.npe4__Type__c = 'Family';
            System.debug('Set relationship to mother');
            relToFather.npe4__Contact__c = student.Id;
            relToFather.npe4__RelatedContact__c = father.Id;
            relToFather.npe4__Description__c = 'Parent/Child';
            relToFather.npe4__Status__c = 'Active';
            relToFather.npe4__Type__c = 'Family';
            System.debug('Set relationship to father');
            //studentInvolvement.Contact__c = student.Id;
            //studentInvolvement.Involvement__r = student.Id;
            studentInvolvement.Involvement_Level__c = 'Student';
            //studentInvolvement.Academic_Semester__c = current.Id;
            studentInvolvement.Grade_Level__c = sa.Grade__c;
            studentInvolvement.Gender__c = sa.Gender__c;
            studentInvolvement.Race__c = sa.Race__c;
            studentInvolvement.Level_Enrolled__c = sa.Enrollment_Level__c;
            studentInvolvement.Date_of_Birth__c = sa.Birthdate__c;
            studentInvolvement.Place_of_Worship__c = sa.Worship_Place__c;
            Semester__c current;
            Integer semCount = [Select Count() From Semester__c a where name = :sa.Academic_Semester__c];
            if(semCount == 0)
            {
               current = new Semester__c(name = sa.Academic_Semester__c);
               semesters.add(current);
            }
            else
            {
                current = [Select Id From Semester__c where name = :sa.Academic_Semester__c];
            }

  • May 28, 2010
  • Like
  • 0

Here is the situation which I find myself in.  My group has setup and object which will accept input via an email service which we have created.  From this object I want to create three contacts and two relationships.  My trigger is as follows, but I have been unable to create a test class that will get more than 0% coverage.  I'm starting to go crazy so I'm hoping someone will be able to point me in the right direction.

 

trigger parseStudentApplication on Student_Application__c (after insert) {

for (Student_Application__c sa : Trigger.new) {

Contact student = new Contact();

Contact father = new Contact();

Contact mother = new Contact();

npe4__Relationship__c studentToFather = new npe4__Relationship__c();

npe4__Relationship__c studentToMother = new npe4__Relationship__c();

student.FirstName = sa.Student_First_Name__c;

student.LastName = sa.Student_Last_Name__c;

student.MailingStreet = sa.Student_Address__c;

student.MailingCity = sa.Student_City__c;

student.MailingState = sa.Student_State__c;

student.MailingPostalCode = sa.Student_Zip__c;

student.Email = sa.Student_Email_Address__c;

student.Phone = sa.Student_Phone__c;

student.Birthdate = sa.Student_Date_of_Birth__c;

father.FirstName = sa.Father_First_Name__c;

father.LastName = sa.Father_Last_Name__c;

if(sa.Father_Address__c == null){

father.MailingStreet = sa.Student_Address__c;

father.MailingCity = sa.Student_City__c;

father.MailingState = sa.Student_State__c;

father.MailingPostalCode = sa.Student_Zip__c;

}

else{

father.MailingStreet = sa.Father_Address__c;

father.MailingCity = sa.Father_City_Text__c;

father.MailingState = sa.Father_State_Text__c;

father.MailingPostalCode = sa.Father_Zip__c;

}

 

if(sa.Mother_Address__c == null){

mother.MailingStreet = sa.Student_Address__c;

mother.MailingCity = sa.Student_City__c;

mother.MailingState = sa.Student_State__c;

mother.MailingPostalCode = sa.Student_Zip__c;

}

else{

mother.MailingStreet = sa.Mother_Address__c;

mother.MailingCity = sa.Mother_City__c;

mother.MailingState = sa.Mother_State__c;

mother.MailingPostalCode = sa.Mother_Zip__c;

}

studentToFather.npe4__Contact__c = student.Id;

studentToFather.npe4__RelatedContact__c = father.Id;

studentToFather.npe4__Description__c = 'Father';

studentToMother.npe4__Contact__c = student.Id;

studentToMother.npe4__RelatedContact__c = mother.Id;

studentToMother.npe4__Description__c = 'Mother';

insert student;

insert father;

insert mother;

insert studentToFather;

insert studentToMother;

}

} 

  • November 24, 2009
  • Like
  • 0

Ok so here is the scenario.  We have an application object which contains information about several entities: 3 contacts and 3 custom objects we have called involvements, one associated with each person.  Inside of the involvement object we have a drop down list with several options and depending on the option you have selected different fields are displayed and different validation rules are applied.  I am not sure if that is what is causing me this issue, but anytime I attempt to insert a new application object I get this error being thrown:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger parseStudentApplication caused an unexpected exception, contact your administrator: parseStudentApplication: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Contact]: [Contact]: Class.StudentApplicationParser.Parse: line 182, column 9

 

The following is my trigger:

trigger parseStudentApplication on Application_For_Admission__c(after insert) {
    List<Application_For_Admission__c> studentApps = Trigger.new;
    {
        StudentApplicationParser sap = new StudentApplicationParser();
        sap.Parse(studentApps);
    } 
}

 

Here is the class that process the trigger:

public with sharing class StudentApplicationParser {
    public void Parse(List<Application_For_Admission__c> sas)
    {
        List<Contact> contacts = new List<Contact>();
        List<Account> accounts = new List<Account>();
        List<npe4__Relationship__c> relationships = new List<npe4__Relationship__c>();
        List<Involvement__c> involvements = new List<Involvement__c>();
        List<Semester__c> semesters = new List<Semester__c>();
        List<School__c> schools = new List<School__c>();
        for(Application_For_Admission__c sa : sas)
        {
            Contact student = new Contact();
            Account studentAcct = new Account();
            Contact mother = new Contact();
            Account motherAcct = new Account();
            Contact father = new Contact();
            Account fatherAcct = new Account();
            npe4__Relationship__c relToMother = new npe4__Relationship__c();
            npe4__Relationship__c relToFather = new npe4__Relationship__c();
            Involvement__c studentInvolvement = new Involvement__c();
            Involvement__c motherInvolvement = new Involvement__c();
            Involvement__c fatherInvolvement = new Involvement__c();
            student.FirstName = sa.First_Name__c;
            student.LastName = sa.Last_Name__c;
            student.Birthdate = sa.Birthdate__c;
            student.MailingStreet = sa.Student_Address__c;
            student.MailingCity = sa.City__c;
            student.MailingState = sa.State__c;
            student.MailingPostalCode = sa.Zip__c;
            student.OtherPhone = sa.Phone__c;
            student.npe01__PreferredPhone__c = 'Other';
            student.npe01__HomeEmail__c = sa.Student_Email_Address__c;
            student.npe01__Preferred_Email__c = 'Home';
            System.debug('Set all student fields');
            mother.FirstName = sa.Mother_First_Name__c;
            mother.LastName = sa.Mother_Last_Name__c;
            mother.npe01__HomeEmail__c = sa.Mother_Email_Address__c;
            mother.npe01__Preferred_Email__c = 'Home';
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.OtherPhone = sa.Mothers_Home_Phone__c;
            mother.npe01__PreferredPhone__c = sa.Mother_Preferred_Phone__c;
            mother.npe01__WorkPhone__c = sa.Mothers_Work_Phone__c;
            mother.MobilePhone = sa.Mothers_Cell_Phone__c;
            if(sa.Mothers_Address__c == null)
            {   
                mother.MailingStreet = sa.Student_Address__c;
                mother.MailingCity = sa.City__c;
                mother.MailingState = sa.State__c;
                mother.MailingPostalCode = sa.Zip__c;
                System.debug('Set all mother fields with same address as child');
            }
            else
            {
                mother.MailingStreet = sa.Mothers_Address__c;
                mother.MailingCity = sa.Mothers_City__c;
                mother.MailingState = sa.Mothers_State__c;
                mother.MailingPostalCode = sa.Mothers_Zip__c;
                System.debug('Set all mother fields with own address');
            }
            father.FirstName = sa.Father_First_Name__c;
            father.LastName = sa.Father_Last_Name__c;
            father.npe01__HomeEmail__c = sa.Father_Email_Address__c;
            father.npe01__Preferred_Email__c = 'Home';
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.OtherPhone = sa.Fathers_Home_Phone__c;
            father.npe01__PreferredPhone__c = sa.Father_Preferred_Phone__c;
            father.npe01__WorkPhone__c = sa.Fathers_Work_Phone__c;
            father.MobilePhone = sa.Fathers_Cell_Phone__c;
            if(sa.Fathers_Address__c == null)
            {
                father.MailingStreet = sa.Student_Address__c;
                father.MailingCity = sa.City__c;
                father.MailingState = sa.State__c;
                father.MailingPostalCode = sa.Zip__c;
                System.debug('Set all father fields with same address as child');
            }
            else
            {
                father.MailingStreet = sa.Fathers_Address__c;
                father.MailingCity = sa.Fathers_City__c;
                father.MailingState = sa.Fathers_State__c;
                father.MailingPostalCode = sa.Fathers_Zip__c;    
                System.debug('Set all father fields with own address');         
            }
            relToMother.npe4__Contact__c = student.Id;
            relToMother.npe4__RelatedContact__c = mother.Id;
            relToMother.npe4__Description__c = 'Parent/Child';      
            relToMother.npe4__Status__c = 'Active'; 
            relToMother.npe4__Type__c = 'Family';
            System.debug('Set relationship to mother');
            relToFather.npe4__Contact__c = student.Id;
            relToFather.npe4__RelatedContact__c = father.Id;
            relToFather.npe4__Description__c = 'Parent/Child';
            relToFather.npe4__Status__c = 'Active';
            relToFather.npe4__Type__c = 'Family';
            System.debug('Set relationship to father');
            //studentInvolvement.Contact__c = student.Id;
            //studentInvolvement.Involvement__r = student.Id;
            studentInvolvement.Involvement_Level__c = 'Student';
            //studentInvolvement.Academic_Semester__c = current.Id;
            studentInvolvement.Grade_Level__c = sa.Grade__c;
            studentInvolvement.Gender__c = sa.Gender__c;
            studentInvolvement.Race__c = sa.Race__c;
            studentInvolvement.Level_Enrolled__c = sa.Enrollment_Level__c;
            studentInvolvement.Date_of_Birth__c = sa.Birthdate__c;
            studentInvolvement.Place_of_Worship__c = sa.Worship_Place__c;
            Semester__c current;
            Integer semCount = [Select Count() From Semester__c a where name = :sa.Academic_Semester__c];
            if(semCount == 0)
            {
               current = new Semester__c(name = sa.Academic_Semester__c);
               semesters.add(current);
            }
            else
            {
                current = [Select Id From Semester__c where name = :sa.Academic_Semester__c];
            }

  • May 28, 2010
  • Like
  • 0

Here is the situation which I find myself in.  My group has setup and object which will accept input via an email service which we have created.  From this object I want to create three contacts and two relationships.  My trigger is as follows, but I have been unable to create a test class that will get more than 0% coverage.  I'm starting to go crazy so I'm hoping someone will be able to point me in the right direction.

 

trigger parseStudentApplication on Student_Application__c (after insert) {

for (Student_Application__c sa : Trigger.new) {

Contact student = new Contact();

Contact father = new Contact();

Contact mother = new Contact();

npe4__Relationship__c studentToFather = new npe4__Relationship__c();

npe4__Relationship__c studentToMother = new npe4__Relationship__c();

student.FirstName = sa.Student_First_Name__c;

student.LastName = sa.Student_Last_Name__c;

student.MailingStreet = sa.Student_Address__c;

student.MailingCity = sa.Student_City__c;

student.MailingState = sa.Student_State__c;

student.MailingPostalCode = sa.Student_Zip__c;

student.Email = sa.Student_Email_Address__c;

student.Phone = sa.Student_Phone__c;

student.Birthdate = sa.Student_Date_of_Birth__c;

father.FirstName = sa.Father_First_Name__c;

father.LastName = sa.Father_Last_Name__c;

if(sa.Father_Address__c == null){

father.MailingStreet = sa.Student_Address__c;

father.MailingCity = sa.Student_City__c;

father.MailingState = sa.Student_State__c;

father.MailingPostalCode = sa.Student_Zip__c;

}

else{

father.MailingStreet = sa.Father_Address__c;

father.MailingCity = sa.Father_City_Text__c;

father.MailingState = sa.Father_State_Text__c;

father.MailingPostalCode = sa.Father_Zip__c;

}

 

if(sa.Mother_Address__c == null){

mother.MailingStreet = sa.Student_Address__c;

mother.MailingCity = sa.Student_City__c;

mother.MailingState = sa.Student_State__c;

mother.MailingPostalCode = sa.Student_Zip__c;

}

else{

mother.MailingStreet = sa.Mother_Address__c;

mother.MailingCity = sa.Mother_City__c;

mother.MailingState = sa.Mother_State__c;

mother.MailingPostalCode = sa.Mother_Zip__c;

}

studentToFather.npe4__Contact__c = student.Id;

studentToFather.npe4__RelatedContact__c = father.Id;

studentToFather.npe4__Description__c = 'Father';

studentToMother.npe4__Contact__c = student.Id;

studentToMother.npe4__RelatedContact__c = mother.Id;

studentToMother.npe4__Description__c = 'Mother';

insert student;

insert father;

insert mother;

insert studentToFather;

insert studentToMother;

}

} 

  • November 24, 2009
  • Like
  • 0