Skip to main content
added 233 characters in body
Source Link
learnjqueery
  • 81
  • 1
  • 2
  • 11
   public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            system.debug('@@@@@' + typeSet);
            system.debug('@@@@@' + csvRecordData[3]);
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
               // **typeAccMaptypeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));**///error;
Set<string> istmpSet happening= heretypeAccMap.get(csvRecordData[0]);
tmpSet.add(Id.valueOf(csvRecordData[3]));
typeAccMap.put(csvRecordData[0], tmpSet);
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insertupsert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                **typeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));**///error is happening here...
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
   public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            system.debug('@@@@@' + typeSet);
            system.debug('@@@@@' + csvRecordData[3]);
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
               // typeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));
Set<string> tmpSet = typeAccMap.get(csvRecordData[0]);
tmpSet.add(Id.valueOf(csvRecordData[3]));
typeAccMap.put(csvRecordData[0], tmpSet);
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
upsert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
added 33 characters in body
Source Link
learnjqueery
  • 81
  • 1
  • 2
  • 11

enter image description hereenter image description here

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                typeAccMap**typeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));;**///error is happening here...
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}

enter image description here

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                typeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}

enter image description here

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                **typeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));**///error is happening here...
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
added 4 characters in body
Source Link
Tushar Sharma
  • 29.7k
  • 7
  • 38
  • 60
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                typeAccMap.put(csvRecordData[0], accmaptypeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                typeAccMap.put(csvRecordData[0], accmap.get(csvRecordData[0]).add(csvRecordData[3]));
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
    public map<string, string> csvmap = new map<string, string>();
    public map<string, Account> accmap = new map<string, Account>();
    List<Type__c> typeList = new List<Type__c>();
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }

  public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 


      for(Integer i=1;i<csvFileLines.size();i++){

           string[] csvRecordData = csvFileLines[i].split(',');
                if(csvmap.containsKey(csvRecordData[0])){
           csvmap.put(csvRecordData[0],csvmap.get(csvRecordData[0])+','+csvRecordData[2]);
               }
                else{
                csvmap.put(csvRecordData[0],csvRecordData[2]) ;
                    }
            }

           system.debug('@@@@@@'+ csvmap);
  /*  for(string str : csvmap.keyset())
     {
       Account accObj = new Account() ;

           accObj.name = str ;             
           accObj.test__c= csvmap.get(str);                                                                      
           acclist.add(accObj); 

      }   

        insert acclist;*/
        for(string str : csvmap.keyset())
{
    Account accObj = new Account() ;
    accObj.name = str ;             
    accObj.test__c= csvmap.get(str);                                                                      
    accmap.put(str , accObj); 
}

insert accmap.values();

Map<Id, set<string>> typeAccMap = new Map<Id, set<string>>();
for(Integer i=1;i<csvFileLines.size();i++){
    string[] csvRecordData = csvFileLines[i].split(',');
    if(accmap.containsKey(csvRecordData[0])){
        Account acc = accmap.get(csvRecordData[0]);
        if(typeAccMap.containsKey(acc.id))
        {
            Set<String> typeSet = typeAccMap.get(acc.id);
            if(! typeSet.contains(csvRecordData[3]))
            {
                Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
                typeList.add(t);
                typeAccMap.put(csvRecordData[0], typeAccMap.get(csvRecordData[0]).add(csvRecordData[3]));
            }
        }
        else
        {
              Type__c t = new Type__c (Name = csvRecordData[3], Account__c = acc.id); 
              typeList.add(t);
              typeAccMap.put(csvRecordData[0], new Set<String>{csvRecordData[3]});
        }

       }
insert typeList;
       }
       }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}
added 298 characters in body
Source Link
learnjqueery
  • 81
  • 1
  • 2
  • 11
Loading
added 107 characters in body
Source Link
learnjqueery
  • 81
  • 1
  • 2
  • 11
Loading
added 1149 characters in body
Source Link
learnjqueery
  • 81
  • 1
  • 2
  • 11
Loading
deleted 27 characters in body
Source Link
Tushar Sharma
  • 29.7k
  • 7
  • 38
  • 60
Loading
Source Link
learnjqueery
  • 81
  • 1
  • 2
  • 11
Loading