+ Start a Discussion
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

CSV upload and update/insert contact logic. Please help

Hey there,

I have created a class using help from this thread: http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html .

I have successfully created a button on my Account visualforce page which allows me to upload a csv, which inserts a fact finder record. This csv also has fields for two contact records. I have attempted to insert these records as well, however the class failed when i tried to insert them as a list.

My questions are:

1.Could someone help me to change my code that it accepts the contact list for upload. Currently when i test it, the code fails at line 55....which is - Constoupload.add(con1);
2.I was hoping to get someone help on some logic. The goal is to make it so that upon upload, the class will check any contacts associated with the account. If they exist then I would want them to be updated with the new information and if they dont then the csv data is inserted. 

Please help and thank you in advance for your help. My class is below.
 
public class FileUploader2 
{
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    public Account Acc{get;set;}
    List<Discovery_Fact_Finder__c> FFtoupload;
    List<Contact> Constoupload;
    public FileUploader2 (ApexPages.StandardController stdController){
    this.Acc = (Account)stdController.getRecord();
    }
    
    public Pagereference ReadFile()
    {
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        FFtoupload = new List<Discovery_Fact_Finder__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            Contact Con1 = new contact();
            Con1.AccountId = acc.id;
            Con1.Title = inputvalues[1];
            Con1.Firstname = inputvalues[2];
            Con1.Middle_Name__c = inputvalues[3];
            Con1.LastName = inputvalues[4];
          //Con1.Birthdate = inputvalues[5];
            Con1.marital_Status__c = inputvalues[6];
            Con1.HomePhone  = inputvalues[7];
            Con1.OtherPhone = inputvalues[8];
            Con1.MobilePhone = inputvalues[9];
            Con1.Fax = inputvalues[10];
            Con1.Email = inputvalues[11];
           //Con1.OtherUnitNo = inputvalues[12];
          //Con1.OtherStreetNo = inputvalues[13];
            Con1.OtherStreet = inputvalues[14];
            Con1.OtherCity = inputvalues[15];
            Con1.OtherState = inputvalues[16];
            Con1.OtherPostalCode = inputvalues[17];
            Con1.OtherCountry = inputvalues[18];
          //Con1.ResidentialDateMovedin = inputvalues[19];
            Con1.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[20]);
          //Con1.MailingUnitNo = inputvalues[21];
          //Con1.MailingStreetNo = inputvalues[22];  
            Con1.MailingStreet = inputvalues[23];
            Con1.MailingCity = inputvalues[24];
            Con1.MailingState = inputvalues[25];
            Con1.MailingPostalcode = inputvalues[26];
            Con1.MailingCountry = inputvalues[27];
          //Con1.Australian_Resident = inputvalues[28];
            Con1.Destiny_VIP__c = Boolean.valueOf(inputvalues[29]);
            
            Constoupload.add(con1);

            
            If(Decimal.valueOf(inputvalues[81]) > 1 ){
            
            Contact Con2 = new contact();
            Con2.AccountId = acc.id;
            Con2.Title = inputvalues[30];
            Con2.Firstname = inputvalues[31];
            Con2.Middle_Name__c = inputvalues[32];
            Con2.LastName = inputvalues[33];
          //Con2.Birthdate = inputvalues[34];
            Con2.marital_Status__c = inputvalues[35];
            Con2.HomePhone  = inputvalues[36];
            Con2.OtherPhone = inputvalues[37];
            Con2.MobilePhone = inputvalues[38];
            Con2.Fax = inputvalues[39];
            Con2.Email = inputvalues[40];
           //Con2.OtherUnitNo = inputvalues[42];
          //Con2.OtherStreetNo = inputvalues[43];
            Con2.OtherStreet = inputvalues[44];
            Con2.OtherCity = inputvalues[45];
            Con2.OtherState = inputvalues[46];
            Con2.OtherPostalCode = inputvalues[47];
            Con2.OtherCountry = inputvalues[48];
          //Con2.ResidentialDateMovedin = inputvalues[49];
            Con2.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[50]);
          //Con2.MailingUnitNo = inputvalues[51];
          //Con2.MailingStreetNo = inputvalues[52];  
            Con2.MailingStreet = inputvalues[53];
            Con2.MailingCity = inputvalues[54];
            Con2.MailingState = inputvalues[55];
            Con2.MailingPostalcode = inputvalues[56];
            Con2.MailingCountry = inputvalues[57];
          //Con2.Australian_Resident = inputvalues[58];
            Con2.Destiny_VIP__c = Boolean.valueOf(inputvalues[59]);
            
            //Constoupload.add(con2);
                                                }
            
            Discovery_Fact_Finder__c FF = new Discovery_Fact_Finder__c();
            FF.Name = inputvalues[0];
            FF.No_Adults_with_Combined_Financials__c = Decimal.valueOf(inputvalues[81]);       
            FF.No_Dependant_Children__c = Decimal.valueOf(inputvalues[82]);
            FF.No_Properties__c = Decimal.valueOf(inputvalues[83]);
            FF.No_Loan_Accounts__c = Decimal.valueOf(inputvalues[84]);
            FF.No_Savings_Accounts__c = Decimal.valueOf(inputvalues[85]);
            FF.Contact_One_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[90]);
            FF.Contact_One_Investment_Property__c   = Decimal.valueOf(inputvalues[91]);
            FF.Contact_One_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[92]);
            FF.Contact_One_Tax_Medicare__c    = Decimal.valueOf(inputvalues[93]);
            FF.Contact_One_Salary_Sacrifice__c    = Decimal.valueOf(inputvalues[94]);
            FF.Contact_One_Family_Benefits__c     = Decimal.valueOf(inputvalues[95]);
            FF.Contact_One_Non_Taxable__c     = Decimal.valueOf(inputvalues[96]);
            FF.Contact_One_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[97]);
            FF.Contact_One_Company_Car__c     = Boolean.valueOf(inputvalues[98]);
            FF.Contact_two_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[99]);
            FF.Contact_two_Investment_Property__c   = Decimal.valueOf(inputvalues[100]);
            FF.Contact_two_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[101]);
            FF.Contact_two_Tax_Medicare__c    = Decimal.valueOf(inputvalues[102]);
            FF.Contact_two_Salary_Sacrifice__c = Decimal.valueOf(inputvalues[103]);
            FF.Contact_Two_Family_Benefits__c = Decimal.valueOf(inputvalues[104]);
            FF.Contact_two_Non_Taxable__c     = Decimal.valueOf(inputvalues[105]);
            FF.Contact_two_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[106]);
            FF.Contact_two_Company_Car__c     = Boolean.valueOf(inputvalues[107]);
            FF.Total_Net_Income__c      = Decimal.valueOf(inputvalues[108]);
            FF.Loan_Payments__c     = Decimal.valueOf(inputvalues[109]);
            FF.Household_Expenses__c   = Decimal.valueOf(inputvalues[110]);
            FF.Medical_Expenses__c  = Decimal.valueOf(inputvalues[111]);
            FF.Motor_Vehicle_Expenses__c = Decimal.valueOf(inputvalues[112]);
            FF.Personal_Expenses__c = Decimal.valueOf(inputvalues[113]);
            FF.Insurance_Expenses__c = Decimal.valueOf(inputvalues[114]);
            FF.Education_Expenses__c = Decimal.valueOf(inputvalues[115]);
            FF.Other_Expenses__c = Decimal.valueOf(inputvalues[116]);
            FF.Investment_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[117]);
            FF.Investment_Non_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[118]);
            FF.Total_Yearly_Expenses__c = Decimal.valueOf(inputvalues[119]);
            FF.Yearly_After_Tax_Personal_Cashflow__c = Decimal.valueOf(inputvalues[120]);
            FF.Personal_Property__c= Decimal.valueOf(inputvalues[121]);
            FF.Personal_Non_Property__c = Decimal.valueOf(inputvalues[122]);
            FF.Investment_Property__c = Decimal.valueOf(inputvalues[123]);
            FF.Investment_Non_Property__c = Decimal.valueOf(inputvalues[124]);
            FF.Savings__c  = Decimal.valueOf(inputvalues[125]);
            FF.Total_Asset_Value__c = Decimal.valueOf(inputvalues[126]);
            FF.Personal_Property_Assets__c = Decimal.valueOf(inputvalues[127]);
            FF.Personal_Non_Property_Assets__c = Decimal.valueOf(inputvalues[128]);
            FF.Investment_Property_Assets__c = Decimal.valueOf(inputvalues[129]);
            FF.Investment_Non_Property_Assets__c = Decimal.valueOf(inputvalues[130]);
            FF.Non_Asset_Linked__c = Decimal.valueOf(inputvalues[131]);
            FF.Total_of_Credit_Card_Limits__c = Decimal.valueOf(inputvalues[132]);
            FF.Total_Debt_Amount__c= Decimal.valueOf(inputvalues[133]);
            FF.Loan_Debt_Balanced__c = Boolean.valueOf(inputvalues[134]);
            FF.Total_Net_Worth_with_Savings__c = Decimal.valueOf(inputvalues[135]);
            FF.Total_Net_Worth_without_Savings__c = Decimal.valueOf(inputvalues[136]);
            FF.Total_Property_Net_Worth__c = Decimal.valueOf(inputvalues[137]);
            FF.Contact_One_Risk_Profile__c = inputvalues[138];
            FF.Contact_Two_Risk_Profile__c = inputvalues[139];
            FF.Account__c = Acc.id;

            FFtoupload.add(FF);
        }
        try{
        insert FFtoupload;
        insert Constoupload;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
            ApexPages.addMessage(errormsg);
        }    
         PageReference p= new PageReference('/apex/DestinyAccount?id='+Acc.id+'&sfdc.override=1');
        p.setRedirect(true);
        p.getParameters().put('tab','Destiny Fact Finder');
        return p;
    }
    
    public List<Discovery_Fact_Finder__c> getuploadedFactFinder()
    {
        if (FFtoupload!= NULL)
            if (FFtoupload.size() > 0)
                return FFtoupload;
            else
                return null;                    
        else
            return null;
    }            
}

 
Best Answer chosen by Developer.mikie.Apex.Student
kaustav goswamikaustav goswami
Let me first explain your first doubt.

You have delared both the lists  List<Discovery_Fact_Finder__c> FFtoupload; and one as List<contact> Constoupload.
You had previosuly instantiated the list List<Discovery_Fact_Finder__c> at line 23. But you did not instantiate the other list. That is why you were facing the issue.

For you second problem I think the following should help:

Declare the following variables:

public Id accId;
Set<String> existConEmails = new Set<String>();
List<Contact> existContacts = new List<Contact>();
List<Contact> toBeUpdatedCon = new List<Contact>();
List<Contact> toBeInsertedCon = new List<Contact>();
// add the following line after the first line of your constructor
accId = Acc.Id; // this will hold the account id for which you will query the contacts
// add the following either in the constructor or at the beginning of the read file method
existContacts = [SELECT Id, Email FROM Contact WHERE AccountId = :accId];
if(existContacts != null && existContacts.size() > 0){
    for(Contact con : existContacts){
        existConEmails.add(con.Email);
    }
}

// now modify the code at line 43 - you need to check if the email exists in the list of contacts you queried from database
// if it exists then you can add it to the uodate list or add it to the insert list
if(existConEmails.contains(inputValues[11])){
    // this means the contact already exists
    // look for the contact record in the list that you fetched from data base and update the attributes on that record
}else {
    // the contact does not exist currently so insert a new record that is add it to the list for insertion
}

Hope this helps.
Thanks,
Kaustav

All Answers

kaustav goswamikaustav goswami
The first issue is probably because you have not instantiated the list.
You need to instantiate the list before you add a contact instance. Like this - 
Constoupload = new List<Contact>();
You can do this in the constructor of the class itself.

As for your second point you can do something like this - 
Add the email ids of the contacts in a list of string
List<String> emailList = new List<String>();
emailList.add(inputValues[11]);

Then query the contacts based on the account id and the email list
SELECT Id, Name, Email FROM Contact WHERE AccountId = :acctId AND Email IN :emailList

Now you can loop over the list of contacts uploaded and add them to the insert list or else add them to the update list (a new list of contact that you will have to declare).

For more efficient approaches you can use map Map<String, Contact> conMap = new Map<String, Contact>();
conMap.put(con.Email, Con); - where con is an instance of the contact record.

Please let me know if this helps.
Thanks,
Kaustav
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Thank you for your reply. I manaed to implement the first solution. I am still not sure why i had to introduce one as
  List<Discovery_Fact_Finder__c> FFtoupload; and one as List<contact> Constoupload = new List<Contact>(); though. 

I am a bit confused on how to implement the second however. I understand lists and can form querries...but i get a little mixed up on the first bit.

Example: (code) = [Select Id, name, Email FROM Contact Where AccountId =:acctId And Email in: emaillist

I have used maps many times before, but normally when i have some help in implementing. 

I was wondering if you could possibly provide some example code on how I may do this querry solution or better yet the more efficient map approach. Thank you for your time.

 

This is my current code:

 

public class FileUploader2 
{
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    public Account Acc{get;set;}
    List<Discovery_Fact_Finder__c> FFtoupload;

    List<contact> Constoupload = new List<Contact>();
    
    Datetime mydate = System.today();

    String S = mydate.format('dd/MM/yyyy');
    
    public FileUploader2 (ApexPages.StandardController stdController){
    this.Acc = (Account)stdController.getRecord();
    }
    
    public Pagereference ReadFile()
    {
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        FFtoupload = new List<Discovery_Fact_Finder__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            If(acc.id == inputvalues[0]){
            
            Contact Con1 = new contact();
            Con1.AccountId = acc.id;
            Con1.Title = inputvalues[1];
            Con1.Firstname = inputvalues[2];
            Con1.Middle_Name__c = inputvalues[3];
            Con1.LastName = inputvalues[4];
          //Con1.Birthdate = inputvalues[5];
            Con1.marital_Status__c = inputvalues[6];
            Con1.HomePhone  = inputvalues[7];
            Con1.Phone = inputvalues[8];
            Con1.MobilePhone = inputvalues[9];
            Con1.Fax = inputvalues[10];
            Con1.Email = inputvalues[11];
           //Con1.OtherUnitNo = inputvalues[12];
          //Con1.OtherStreetNo = inputvalues[13];
            Con1.OtherStreet = inputvalues[14];
            Con1.OtherCity = inputvalues[15];
            Con1.OtherState = inputvalues[16];
            Con1.OtherPostalCode = inputvalues[17];
            Con1.OtherCountry = inputvalues[18];
          //Con1.ResidentialDateMovedin = inputvalues[19];
            Con1.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[20]);
          //Con1.MailingUnitNo = inputvalues[21];
          //Con1.MailingStreetNo = inputvalues[22];  
            Con1.MailingStreet = inputvalues[23];
            Con1.MailingCity = inputvalues[24];
            Con1.MailingState = inputvalues[25];
            Con1.MailingPostalcode = inputvalues[26];
            Con1.MailingCountry = inputvalues[27];
          //Con1.Australian_Resident = inputvalues[28];
            Con1.Destiny_VIP__c = Boolean.valueOf(inputvalues[29]);
            
            Constoupload.add(con1);

            
            If(Decimal.valueOf(inputvalues[81]) > 1 ){
            
            Contact Con2 = new contact();
            Con2.AccountId = acc.id;
            Con2.Title = inputvalues[30];
            Con2.Firstname = inputvalues[31];
            Con2.Middle_Name__c = inputvalues[32];
            Con2.LastName = inputvalues[33];
          //Con2.Birthdate = inputvalues[34];
            Con2.marital_Status__c = inputvalues[35];
            Con2.HomePhone  = inputvalues[36];
            Con2.Phone = inputvalues[37];
            Con2.MobilePhone = inputvalues[38];
            Con2.Fax = inputvalues[39];
            Con2.Email = inputvalues[40];
           //Con2.OtherUnitNo = inputvalues[42];
          //Con2.OtherStreetNo = inputvalues[43];
            Con2.OtherStreet = inputvalues[44];
            Con2.OtherCity = inputvalues[45];
            Con2.OtherState = inputvalues[46];
            Con2.OtherPostalCode = inputvalues[47];
            Con2.OtherCountry = inputvalues[48];
          //Con2.ResidentialDateMovedin = inputvalues[49];
            Con2.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[50]);
          //Con2.MailingUnitNo = inputvalues[51];
          //Con2.MailingStreetNo = inputvalues[52];  
            Con2.MailingStreet = inputvalues[53];
            Con2.MailingCity = inputvalues[54];
            Con2.MailingState = inputvalues[55];
            Con2.MailingPostalcode = inputvalues[56];
            Con2.MailingCountry = inputvalues[57];
          //Con2.Australian_Resident = inputvalues[58];
            Con2.Destiny_VIP__c = Boolean.valueOf(inputvalues[59]);
            
            //Constoupload.add(con2);
                                                }
            
            Discovery_Fact_Finder__c FF = new Discovery_Fact_Finder__c();
            FF.Name = acc.name+' -Discovery# '+S;
            FF.No_Adults_with_Combined_Financials__c = Decimal.valueOf(inputvalues[81]);       
            FF.No_Dependant_Children__c = Decimal.valueOf(inputvalues[82]);
            FF.No_Properties__c = Decimal.valueOf(inputvalues[83]);
            FF.No_Loan_Accounts__c = Decimal.valueOf(inputvalues[84]);
            FF.No_Savings_Accounts__c = Decimal.valueOf(inputvalues[85]);
            FF.Contact_One_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[90]);
            FF.Contact_One_Investment_Property__c   = Decimal.valueOf(inputvalues[91]);
            FF.Contact_One_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[92]);
            FF.Contact_One_Tax_Medicare__c    = Decimal.valueOf(inputvalues[93]);
            FF.Contact_One_Salary_Sacrifice__c    = Decimal.valueOf(inputvalues[94]);
            FF.Contact_One_Family_Benefits__c     = Decimal.valueOf(inputvalues[95]);
            FF.Contact_One_Non_Taxable__c     = Decimal.valueOf(inputvalues[96]);
            FF.Contact_One_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[97]);
            FF.Contact_One_Company_Car__c     = Boolean.valueOf(inputvalues[98]);
            FF.Contact_two_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[99]);
            FF.Contact_two_Investment_Property__c   = Decimal.valueOf(inputvalues[100]);
            FF.Contact_two_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[101]);
            FF.Contact_two_Tax_Medicare__c    = Decimal.valueOf(inputvalues[102]);
            FF.Contact_two_Salary_Sacrifice__c = Decimal.valueOf(inputvalues[103]);
            FF.Contact_Two_Family_Benefits__c = Decimal.valueOf(inputvalues[104]);
            FF.Contact_two_Non_Taxable__c     = Decimal.valueOf(inputvalues[105]);
            FF.Contact_two_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[106]);
            FF.Contact_two_Company_Car__c     = Boolean.valueOf(inputvalues[107]);
            FF.Total_Net_Income__c      = Decimal.valueOf(inputvalues[108]);
            FF.Loan_Payments__c     = Decimal.valueOf(inputvalues[109]);
            FF.Household_Expenses__c   = Decimal.valueOf(inputvalues[110]);
            FF.Medical_Expenses__c  = Decimal.valueOf(inputvalues[111]);
            FF.Motor_Vehicle_Expenses__c = Decimal.valueOf(inputvalues[112]);
            FF.Personal_Expenses__c = Decimal.valueOf(inputvalues[113]);
            FF.Insurance_Expenses__c = Decimal.valueOf(inputvalues[114]);
            FF.Education_Expenses__c = Decimal.valueOf(inputvalues[115]);
            FF.Other_Expenses__c = Decimal.valueOf(inputvalues[116]);
            FF.Investment_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[117]);
            FF.Investment_Non_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[118]);
            FF.Total_Yearly_Expenses__c = Decimal.valueOf(inputvalues[119]);
            FF.Yearly_After_Tax_Personal_Cashflow__c = Decimal.valueOf(inputvalues[120]);
            FF.Personal_Property__c= Decimal.valueOf(inputvalues[121]);
            FF.Personal_Non_Property__c = Decimal.valueOf(inputvalues[122]);
            FF.Investment_Property__c = Decimal.valueOf(inputvalues[123]);
            FF.Investment_Non_Property__c = Decimal.valueOf(inputvalues[124]);
            FF.Savings__c  = Decimal.valueOf(inputvalues[125]);
            FF.Total_Asset_Value__c = Decimal.valueOf(inputvalues[126]);
            FF.Personal_Property_Assets__c = Decimal.valueOf(inputvalues[127]);
            FF.Personal_Non_Property_Assets__c = Decimal.valueOf(inputvalues[128]);
            FF.Investment_Property_Assets__c = Decimal.valueOf(inputvalues[129]);
            FF.Investment_Non_Property_Assets__c = Decimal.valueOf(inputvalues[130]);
            FF.Non_Asset_Linked__c = Decimal.valueOf(inputvalues[131]);
            FF.Total_of_Credit_Card_Limits__c = Decimal.valueOf(inputvalues[132]);
            FF.Total_Debt_Amount__c= Decimal.valueOf(inputvalues[133]);
            FF.Loan_Debt_Balanced__c = Boolean.valueOf(inputvalues[134]);
            FF.Total_Net_Worth_with_Savings__c = Decimal.valueOf(inputvalues[135]);
            FF.Total_Net_Worth_without_Savings__c = Decimal.valueOf(inputvalues[136]);
            FF.Total_Property_Net_Worth__c = Decimal.valueOf(inputvalues[137]);
            FF.Contact_One_Risk_Profile__c = inputvalues[138];
            FF.Contact_Two_Risk_Profile__c = inputvalues[139];
            FF.Account__c = Acc.id;

            FFtoupload.add(FF);
            
                 }else{
                                ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'The AccountID from the Discovery document does not match the page ID.');
                               
            ApexPages.addMessage(errormsg);
            return null;
            }
                                
        }
        try{
        insert FFtoupload;
        insert Constoupload;
        
        PageReference p= new PageReference('/apex/DestinyAccount?id='+Acc.id+'&sfdc.override=1');
        p.setRedirect(true);
        p.getParameters().put('tab','Destiny Fact Finder');
        return p;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
            ApexPages.addMessage(errormsg);
        }    
                                        
         return null;
         
    }
    
    public List<Discovery_Fact_Finder__c> getuploadedFactFinder()
    {
        if (FFtoupload!= NULL)
            if (FFtoupload.size() > 0)
                return FFtoupload;
            else
                return null;                    
        else
            return null;
    }            
}
kaustav goswamikaustav goswami
Let me first explain your first doubt.

You have delared both the lists  List<Discovery_Fact_Finder__c> FFtoupload; and one as List<contact> Constoupload.
You had previosuly instantiated the list List<Discovery_Fact_Finder__c> at line 23. But you did not instantiate the other list. That is why you were facing the issue.

For you second problem I think the following should help:

Declare the following variables:

public Id accId;
Set<String> existConEmails = new Set<String>();
List<Contact> existContacts = new List<Contact>();
List<Contact> toBeUpdatedCon = new List<Contact>();
List<Contact> toBeInsertedCon = new List<Contact>();
// add the following line after the first line of your constructor
accId = Acc.Id; // this will hold the account id for which you will query the contacts
// add the following either in the constructor or at the beginning of the read file method
existContacts = [SELECT Id, Email FROM Contact WHERE AccountId = :accId];
if(existContacts != null && existContacts.size() > 0){
    for(Contact con : existContacts){
        existConEmails.add(con.Email);
    }
}

// now modify the code at line 43 - you need to check if the email exists in the list of contacts you queried from database
// if it exists then you can add it to the uodate list or add it to the insert list
if(existConEmails.contains(inputValues[11])){
    // this means the contact already exists
    // look for the contact record in the list that you fetched from data base and update the attributes on that record
}else {
    // the contact does not exist currently so insert a new record that is add it to the list for insertion
}

Hope this helps.
Thanks,
Kaustav
This was selected as the best answer
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Thank you so much for your amazing help so far. I have managed to get nearly everything working, except the update a contact with the same email. The inserts work, but there is something stopping the update from working. This is my current code:
 
public class FileUploader2 
{
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    public Account Acc{get;set;}
    List<Discovery_Fact_Finder__c> FFtoupload;

    
    public Id accId;
    Set<String> existConEmails = new Set<String>();
    List<Contact> existContacts = new List<Contact>();
    List<Contact> toBeUpdatedCon = new List<Contact>();
    List<Contact> toBeInsertedCon = new List<Contact>();
    
    Datetime mydate = System.today();
    String S = mydate.format('dd/MM/yyyy');
    
    public FileUploader2 (ApexPages.StandardController stdController){
    this.Acc = (Account)stdController.getRecord();
    accId = Acc.Id; // this will hold the account id for which you will query the contacts
    }
    
    public Pagereference ReadFile()
    {
    
        existContacts = [SELECT Id, Email FROM Contact WHERE AccountId = :accId];
        if(existContacts != null && existContacts.size() > 0){
            for(Contact con : existContacts){
        existConEmails.add(con.Email);
                            }
                                                    }
    
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        FFtoupload = new List<Discovery_Fact_Finder__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            If(acc.id == inputvalues[0]){
            
            Contact Con1 = new contact();
            Con1.AccountId = acc.id;
            Con1.Title = inputvalues[1];
            Con1.Firstname = inputvalues[2];
            Con1.Middle_Name__c = inputvalues[3];
            Con1.LastName = inputvalues[4];
          //Con1.Birthdate = inputvalues[5];
            Con1.marital_Status__c = inputvalues[6];
            Con1.HomePhone  = inputvalues[7];
            Con1.Phone = inputvalues[8];
            Con1.MobilePhone = inputvalues[9];
            Con1.Fax = inputvalues[10];
            Con1.Email = inputvalues[11];
           //Con1.OtherUnitNo = inputvalues[12];
          //Con1.OtherStreetNo = inputvalues[13];
            Con1.OtherStreet = inputvalues[14];
            Con1.OtherCity = inputvalues[15];
            Con1.OtherState = inputvalues[16];
            Con1.OtherPostalCode = inputvalues[17];
            Con1.OtherCountry = inputvalues[18];
          //Con1.ResidentialDateMovedin = inputvalues[19];
            Con1.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[20]);
          //Con1.MailingUnitNo = inputvalues[21];
          //Con1.MailingStreetNo = inputvalues[22];  
            Con1.MailingStreet = inputvalues[23];
            Con1.MailingCity = inputvalues[24];
            Con1.MailingState = inputvalues[25];
            Con1.MailingPostalcode = inputvalues[26];
            Con1.MailingCountry = inputvalues[27];
          //Con1.Australian_Resident = inputvalues[28];
            Con1.Destiny_VIP__c = Boolean.valueOf(inputvalues[29]);
            
            if(existConEmails.contains(inputValues[11])){
                       toBeUpdatedCon.add(con1);
            // look for the contact record in the list that you fetched from data base and update the attributes on that record
            }else {    toBeInsertedCon.add(con1);
    // the contact does not exist currently so insert a new record that is add it to the list for insertion
            }


            
            If(Decimal.valueOf(inputvalues[81]) > 1 ){
            
            Contact Con2 = new contact();
            Con2.AccountId = acc.id;
            Con2.Title = inputvalues[30];
            Con2.Firstname = inputvalues[31];
            Con2.Middle_Name__c = inputvalues[32];
            Con2.LastName = inputvalues[33];
          //Con2.Birthdate = inputvalues[34];
            Con2.marital_Status__c = inputvalues[35];
            Con2.HomePhone  = inputvalues[36];
            Con2.Phone = inputvalues[37];
            Con2.MobilePhone = inputvalues[38];
            Con2.Fax = inputvalues[39];
            Con2.Email = inputvalues[40];
           //Con2.OtherUnitNo = inputvalues[42];
          //Con2.OtherStreetNo = inputvalues[43];
            Con2.OtherStreet = inputvalues[44];
            Con2.OtherCity = inputvalues[45];
            Con2.OtherState = inputvalues[46];
            Con2.OtherPostalCode = inputvalues[47];
            Con2.OtherCountry = inputvalues[48];
          //Con2.ResidentialDateMovedin = inputvalues[49];
            Con2.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[50]);
          //Con2.MailingUnitNo = inputvalues[51];
          //Con2.MailingStreetNo = inputvalues[52];  
            Con2.MailingStreet = inputvalues[53];
            Con2.MailingCity = inputvalues[54];
            Con2.MailingState = inputvalues[55];
            Con2.MailingPostalcode = inputvalues[56];
            Con2.MailingCountry = inputvalues[57];
          //Con2.Australian_Resident = inputvalues[58];
            Con2.Destiny_VIP__c = Boolean.valueOf(inputvalues[59]);
            
            if(existConEmails.contains(inputValues[40])){
                       toBeUpdatedCon.add(con2);
            // look for the contact record in the list that you fetched from data base and update the attributes on that record
            }else {    toBeInsertedCon.add(con2);
            // the contact does not exist currently so insert a new record that is add it to the list for insertion
            }                                                }
            
            Discovery_Fact_Finder__c FF = new Discovery_Fact_Finder__c();
            FF.Name = acc.name+' - Discovery# '+S;
            FF.No_Adults_with_Combined_Financials__c = Decimal.valueOf(inputvalues[81]);       
            FF.No_Dependant_Children__c = Decimal.valueOf(inputvalues[82]);
            FF.No_Properties__c = Decimal.valueOf(inputvalues[83]);
            FF.No_Loan_Accounts__c = Decimal.valueOf(inputvalues[84]);
            FF.No_Savings_Accounts__c = Decimal.valueOf(inputvalues[85]);
            FF.Contact_One_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[90]);
            FF.Contact_One_Investment_Property__c   = Decimal.valueOf(inputvalues[91]);
            FF.Contact_One_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[92]);
            FF.Contact_One_Tax_Medicare__c    = Decimal.valueOf(inputvalues[93]);
            FF.Contact_One_Salary_Sacrifice__c    = Decimal.valueOf(inputvalues[94]);
            FF.Contact_One_Family_Benefits__c     = Decimal.valueOf(inputvalues[95]);
            FF.Contact_One_Non_Taxable__c     = Decimal.valueOf(inputvalues[96]);
            FF.Contact_One_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[97]);
            FF.Contact_One_Company_Car__c     = Boolean.valueOf(inputvalues[98]);
            FF.Contact_two_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[99]);
            FF.Contact_two_Investment_Property__c   = Decimal.valueOf(inputvalues[100]);
            FF.Contact_two_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[101]);
            FF.Contact_two_Tax_Medicare__c    = Decimal.valueOf(inputvalues[102]);
            FF.Contact_two_Salary_Sacrifice__c = Decimal.valueOf(inputvalues[103]);
            FF.Contact_Two_Family_Benefits__c = Decimal.valueOf(inputvalues[104]);
            FF.Contact_two_Non_Taxable__c     = Decimal.valueOf(inputvalues[105]);
            FF.Contact_two_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[106]);
            FF.Contact_two_Company_Car__c     = Boolean.valueOf(inputvalues[107]);
            FF.Total_Net_Income__c      = Decimal.valueOf(inputvalues[108]);
            FF.Loan_Payments__c     = Decimal.valueOf(inputvalues[109]);
            FF.Household_Expenses__c   = Decimal.valueOf(inputvalues[110]);
            FF.Medical_Expenses__c  = Decimal.valueOf(inputvalues[111]);
            FF.Motor_Vehicle_Expenses__c = Decimal.valueOf(inputvalues[112]);
            FF.Personal_Expenses__c = Decimal.valueOf(inputvalues[113]);
            FF.Insurance_Expenses__c = Decimal.valueOf(inputvalues[114]);
            FF.Education_Expenses__c = Decimal.valueOf(inputvalues[115]);
            FF.Other_Expenses__c = Decimal.valueOf(inputvalues[116]);
            FF.Investment_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[117]);
            FF.Investment_Non_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[118]);
            FF.Total_Yearly_Expenses__c = Decimal.valueOf(inputvalues[119]);
            FF.Yearly_After_Tax_Personal_Cashflow__c = Decimal.valueOf(inputvalues[120]);
            FF.Personal_Property__c= Decimal.valueOf(inputvalues[121]);
            FF.Personal_Non_Property__c = Decimal.valueOf(inputvalues[122]);
            FF.Investment_Property__c = Decimal.valueOf(inputvalues[123]);
            FF.Investment_Non_Property__c = Decimal.valueOf(inputvalues[124]);
            FF.Savings__c  = Decimal.valueOf(inputvalues[125]);
            FF.Total_Asset_Value__c = Decimal.valueOf(inputvalues[126]);
            FF.Personal_Property_Assets__c = Decimal.valueOf(inputvalues[127]);
            FF.Personal_Non_Property_Assets__c = Decimal.valueOf(inputvalues[128]);
            FF.Investment_Property_Assets__c = Decimal.valueOf(inputvalues[129]);
            FF.Investment_Non_Property_Assets__c = Decimal.valueOf(inputvalues[130]);
            FF.Non_Asset_Linked__c = Decimal.valueOf(inputvalues[131]);
            FF.Total_of_Credit_Card_Limits__c = Decimal.valueOf(inputvalues[132]);
            FF.Total_Debt_Amount__c= Decimal.valueOf(inputvalues[133]);
            FF.Loan_Debt_Balanced__c = Boolean.valueOf(inputvalues[134]);
            FF.Total_Net_Worth_with_Savings__c = Decimal.valueOf(inputvalues[135]);
            FF.Total_Net_Worth_without_Savings__c = Decimal.valueOf(inputvalues[136]);
            FF.Total_Property_Net_Worth__c = Decimal.valueOf(inputvalues[137]);
            FF.Contact_One_Risk_Profile__c = inputvalues[138];
            FF.Contact_Two_Risk_Profile__c = inputvalues[139];
            FF.Account__c = Acc.id;

            FFtoupload.add(FF);
            
                 }else{
                                ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'The AccountID from the Discovery document does not match the page ID.');
                               
            ApexPages.addMessage(errormsg);
            return null;
            }
                                
        }
        try{
        insert FFtoupload;
        insert toBeInsertedCon;
        Update toBeUpdatedCon;
        
        PageReference p= new PageReference('/apex/DestinyAccount?id='+Acc.id+'&sfdc.override=1');
        p.setRedirect(true);
        p.getParameters().put('tab','Destiny Fact Finder');
        return p;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
            ApexPages.addMessage(errormsg);
        }    
                                        
         return null;
         
    }
    
    public List<Discovery_Fact_Finder__c> getuploadedFactFinder()
    {
        if (FFtoupload!= NULL)
            if (FFtoupload.size() > 0)
                return FFtoupload;
            else
                return null;                    
        else
            return null;
    }            
}

 
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Managed to solve the problem with maps. Thank you so much for your help.

 

This was the finished code, it works...it just hasnt been tested as i cant figure out how to write a test clas for it.

 

public class FileUploader2 
{
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    public Account Acc{get;set;}
    List<Discovery_Fact_Finder__c> FFtoupload;

    
    public Id accId;
    Set<String> existConEmails = new Set<String>();
    List<Contact> existContacts = new List<Contact>();
    List<Contact> toBeUpdatedCon = new List<Contact>();
    List<Contact> toBeInsertedCon = new List<Contact>();
    
    Map<String, ID> ConMap = new Map<String, ID>(); // Define a new map
    
    Datetime mydate = System.today();
    String S = mydate.format('dd/MM/yyyy');
    
    public FileUploader2 (ApexPages.StandardController stdController){
    this.Acc = (Account)stdController.getRecord();
    accId = Acc.Id; // this will hold the account id for which you will query the contacts
    }
    
    public Pagereference ReadFile()
    {
    
        existContacts = [SELECT Id, Email FROM Contact WHERE AccountId = :accId];
        if(existContacts != null && existContacts.size() > 0){
            for(Contact con : existContacts){
        existConEmails.add(con.Email);
        ConMap.put(con.Email, con.Id);
                            }
                                                    }
    
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        FFtoupload = new List<Discovery_Fact_Finder__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            If(acc.id == inputvalues[0]){
            
            Contact Con1 = new contact();
            Con1.AccountId = acc.id;
            Con1.Title = inputvalues[1];
            Con1.Firstname = inputvalues[2];
            Con1.Middle_Name__c = inputvalues[3];
            Con1.LastName = inputvalues[4];
          //Con1.Birthdate = inputvalues[5];
            Con1.marital_Status__c = inputvalues[6];
            Con1.HomePhone  = inputvalues[7];
            Con1.Phone = inputvalues[8];
            Con1.MobilePhone = inputvalues[9];
            Con1.Fax = inputvalues[10];
            Con1.Email = inputvalues[11];
           //Con1.OtherUnitNo = inputvalues[12];
          //Con1.OtherStreetNo = inputvalues[13];
            Con1.OtherStreet = inputvalues[14];
            Con1.OtherCity = inputvalues[15];
            Con1.OtherState = inputvalues[16];
            Con1.OtherPostalCode = inputvalues[17];
            Con1.OtherCountry = inputvalues[18];
          //Con1.ResidentialDateMovedin = inputvalues[19];
            Con1.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[20]);
          //Con1.MailingUnitNo = inputvalues[21];
          //Con1.MailingStreetNo = inputvalues[22];  
            Con1.MailingStreet = inputvalues[23];
            Con1.MailingCity = inputvalues[24];
            Con1.MailingState = inputvalues[25];
            Con1.MailingPostalcode = inputvalues[26];
            Con1.MailingCountry = inputvalues[27];
          //Con1.Australian_Resident = inputvalues[28];
            Con1.Destiny_VIP__c = Boolean.valueOf(inputvalues[29]);
            
            if(existConEmails.contains(inputValues[11])){
            
                       con1.id =  ConMap.get(inputvalues[11]);

                       toBeUpdatedCon.add(con1);
            // look for the contact record in the list that you fetched from data base and update the attributes on that record
            }else {    toBeInsertedCon.add(con1);
    // the contact does not exist currently so insert a new record that is add it to the list for insertion
            }


            
            If(Decimal.valueOf(inputvalues[81]) > 1 ){
            
            Contact Con2 = new contact();
            Con2.AccountId = acc.id;
            Con2.Title = inputvalues[30];
            Con2.Firstname = inputvalues[31];
            Con2.Middle_Name__c = inputvalues[32];
            Con2.LastName = inputvalues[33];
          //Con2.Birthdate = inputvalues[34];
            Con2.marital_Status__c = inputvalues[35];
            Con2.HomePhone  = inputvalues[36];
            Con2.Phone = inputvalues[37];
            Con2.MobilePhone = inputvalues[38];
            Con2.Fax = inputvalues[39];
            Con2.Email = inputvalues[40];
           //Con2.OtherUnitNo = inputvalues[42];
          //Con2.OtherStreetNo = inputvalues[43];
            Con2.OtherStreet = inputvalues[44];
            Con2.OtherCity = inputvalues[45];
            Con2.OtherState = inputvalues[46];
            Con2.OtherPostalCode = inputvalues[47];
            Con2.OtherCountry = inputvalues[48];
          //Con2.ResidentialDateMovedin = inputvalues[49];
            Con2.Postal_Address_Residential_Address__c = Boolean.valueOf(inputvalues[50]);
          //Con2.MailingUnitNo = inputvalues[51];
          //Con2.MailingStreetNo = inputvalues[52];  
            Con2.MailingStreet = inputvalues[53];
            Con2.MailingCity = inputvalues[54];
            Con2.MailingState = inputvalues[55];
            Con2.MailingPostalcode = inputvalues[56];
            Con2.MailingCountry = inputvalues[57];
          //Con2.Australian_Resident = inputvalues[58];
            Con2.Destiny_VIP__c = Boolean.valueOf(inputvalues[59]);
            
            if(existConEmails.contains(inputValues[40])){
            
                       con2.id =  ConMap.get(inputvalues[40]);
                       toBeUpdatedCon.add(con2);
            // look for the contact record in the list that you fetched from data base and update the attributes on that record
            }else {    toBeInsertedCon.add(con2);
            // the contact does not exist currently so insert a new record that is add it to the list for insertion
            }                                                }
            
            Discovery_Fact_Finder__c FF = new Discovery_Fact_Finder__c();
            FF.Name = acc.name+' - Discovery# '+S;
            FF.No_Adults_with_Combined_Financials__c = Decimal.valueOf(inputvalues[81]);       
            FF.No_Dependant_Children__c = Decimal.valueOf(inputvalues[82]);
            FF.No_Properties__c = Decimal.valueOf(inputvalues[83]);
            FF.No_Loan_Accounts__c = Decimal.valueOf(inputvalues[84]);
            FF.No_Savings_Accounts__c = Decimal.valueOf(inputvalues[85]);
            FF.Contact_One_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[90]);
            FF.Contact_One_Investment_Property__c   = Decimal.valueOf(inputvalues[91]);
            FF.Contact_One_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[92]);
            FF.Contact_One_Tax_Medicare__c    = Decimal.valueOf(inputvalues[93]);
            FF.Contact_One_Salary_Sacrifice__c    = Decimal.valueOf(inputvalues[94]);
            FF.Contact_One_Family_Benefits__c     = Decimal.valueOf(inputvalues[95]);
            FF.Contact_One_Non_Taxable__c     = Decimal.valueOf(inputvalues[96]);
            FF.Contact_One_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[97]);
            FF.Contact_One_Company_Car__c     = Boolean.valueOf(inputvalues[98]);
            FF.Contact_two_Personal_Gross_Taxable__c  = Decimal.valueOf(inputvalues[99]);
            FF.Contact_two_Investment_Property__c   = Decimal.valueOf(inputvalues[100]);
            FF.Contact_two_Non_Property_Asset__c    = Decimal.valueOf(inputvalues[101]);
            FF.Contact_two_Tax_Medicare__c    = Decimal.valueOf(inputvalues[102]);
            FF.Contact_two_Salary_Sacrifice__c = Decimal.valueOf(inputvalues[103]);
            FF.Contact_Two_Family_Benefits__c = Decimal.valueOf(inputvalues[104]);
            FF.Contact_two_Non_Taxable__c     = Decimal.valueOf(inputvalues[105]);
            FF.Contact_two_Net_Yearly_Income__c     = Decimal.valueOf(inputvalues[106]);
            FF.Contact_two_Company_Car__c     = Boolean.valueOf(inputvalues[107]);
            FF.Total_Net_Income__c      = Decimal.valueOf(inputvalues[108]);
            FF.Loan_Payments__c     = Decimal.valueOf(inputvalues[109]);
            FF.Household_Expenses__c   = Decimal.valueOf(inputvalues[110]);
            FF.Medical_Expenses__c  = Decimal.valueOf(inputvalues[111]);
            FF.Motor_Vehicle_Expenses__c = Decimal.valueOf(inputvalues[112]);
            FF.Personal_Expenses__c = Decimal.valueOf(inputvalues[113]);
            FF.Insurance_Expenses__c = Decimal.valueOf(inputvalues[114]);
            FF.Education_Expenses__c = Decimal.valueOf(inputvalues[115]);
            FF.Other_Expenses__c = Decimal.valueOf(inputvalues[116]);
            FF.Investment_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[117]);
            FF.Investment_Non_Property_Assets_Expenses__c = Decimal.valueOf(inputvalues[118]);
            FF.Total_Yearly_Expenses__c = Decimal.valueOf(inputvalues[119]);
            FF.Yearly_After_Tax_Personal_Cashflow__c = Decimal.valueOf(inputvalues[120]);
            FF.Personal_Property__c= Decimal.valueOf(inputvalues[121]);
            FF.Personal_Non_Property__c = Decimal.valueOf(inputvalues[122]);
            FF.Investment_Property__c = Decimal.valueOf(inputvalues[123]);
            FF.Investment_Non_Property__c = Decimal.valueOf(inputvalues[124]);
            FF.Savings__c  = Decimal.valueOf(inputvalues[125]);
            FF.Total_Asset_Value__c = Decimal.valueOf(inputvalues[126]);
            FF.Personal_Property_Assets__c = Decimal.valueOf(inputvalues[127]);
            FF.Personal_Non_Property_Assets__c = Decimal.valueOf(inputvalues[128]);
            FF.Investment_Property_Assets__c = Decimal.valueOf(inputvalues[129]);
            FF.Investment_Non_Property_Assets__c = Decimal.valueOf(inputvalues[130]);
            FF.Non_Asset_Linked__c = Decimal.valueOf(inputvalues[131]);
            FF.Total_of_Credit_Card_Limits__c = Decimal.valueOf(inputvalues[132]);
            FF.Total_Debt_Amount__c= Decimal.valueOf(inputvalues[133]);
            FF.Loan_Debt_Balanced__c = Boolean.valueOf(inputvalues[134]);
            FF.Total_Net_Worth_with_Savings__c = Decimal.valueOf(inputvalues[135]);
            FF.Total_Net_Worth_without_Savings__c = Decimal.valueOf(inputvalues[136]);
            FF.Total_Property_Net_Worth__c = Decimal.valueOf(inputvalues[137]);
            FF.Contact_One_Risk_Profile__c = inputvalues[138];
            FF.Contact_Two_Risk_Profile__c = inputvalues[139];
            FF.Account__c = Acc.id;

            FFtoupload.add(FF);
            
                 }else{
                                ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'The AccountID from the Discovery document does not match the page ID.');
                               
            ApexPages.addMessage(errormsg);
            return null;
            }
                                
        }
        try{
        
        if(FFtoupload.size()>0)
{
        insert FFtoupload;
        }
        if(toBeInsertedCon.size()>0)
{
        insert toBeInsertedCon;
        }
        if(toBeUpdatedCon.size()>0)
{
        Update toBeUpdatedCon;
        }
        
        PageReference p= new PageReference('/apex/DestinyAccount?id='+Acc.id+'&sfdc.override=1');
        p.setRedirect(true);
        p.getParameters().put('tab','Destiny Fact Finder');
        return p;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
            ApexPages.addMessage(errormsg);
        }    
                                        
         return null;
         
    }
    
    public List<Discovery_Fact_Finder__c> getuploadedFactFinder()
    {
        if (FFtoupload!= NULL)
            if (FFtoupload.size() > 0)
                return FFtoupload;
            else
                return null;                    
        else
            return null;
    }            
}