• Sales person 375
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Im new to salesforce, im working on visualforce page to import Account and contacts to salesforce.

here is my requiremnt, please guide me to achive this. 
 
Give the customer ability to import Accounts from external csv file to salesforce with button on custom Visualforce page.
Read the csv file and display the content in the Tabular form in the same Visualforce page.
Verify the Duplicate records based on Phone number, if the phone number of the import record matches with existing Account record then verify for Email field match, if matches then populate error message as Duplicate record on Visualforce page Table under Status column for particular record. Otherwise insert record and update the status column on Visualforce page as Success.
Extend the functionality to multiple Objects (Account, Contact, and Opportunity) from single csv file.

here is my code: im getting error "common.apex.runtime.impl.ExecutionException: List index out of bounds: 5" and status is not getting updated. 

Please help me

VF:
<apex:page controller="importDataFromCSVController">
    <apex:form >
        <apex:pagemessages />
        <apex:pageBlock >
            <apex:pageBlockSection columns="4">
                  <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
                  <apex:commandButton value="Import Account" action="{!importCSVFile}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock >
           <apex:pageblocktable value="{!accList}" var="acc">
              <apex:column value="{!acc.name}" />
              <apex:column value="{!acc.AccountNumber}" />
              <apex:column value="{!acc.Type}" />
              <apex:column value="{!acc.Accountsource}" />
              <apex:column value="{!acc.Industry }" />
               <apex:column headerValue="Status" >
              <apex:outputText id="status"/>
              </apex:column>
           </apex:pageblocktable>
        </apex:pageBlock>
   </apex:form>
</apex:page>

Apex Class:

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public string csvStatus{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
public string[] csvRecordData;
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++)
           {
               Account accObj = new Account() ;
               csvRecordData = csvFileLines[i].split(',');
               accObj.name = csvRecordData[0] ;            
               accObj.accountnumber = csvRecordData[1];
               accObj.Type = csvRecordData[2];
               accObj.AccountSource = csvRecordData[3];  
               accObj.Industry = csvRecordData[4];
               uploadStatus(accObj);
               csvRecordData[5] = csvStatus;
            }
        insert acclist;
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'error here');
            ApexPages.addMessage(errorMessage);
        } 
  }
  
public List<Account> uploadStatus(Account a)
   {
       for(Account acc:[SELECT Name, Accountnumber FROM Account])
       {
           if(acc.name == a.name && acc.accountnumber == a.accountnumber)
           {
               this.csvStatus = 'Duplicate';
                system.debug('inside if');
           }
           else
           {
               system.debug('inside else');
               acclist.add(a);
               this.csvStatus = 'unique';
               
           }
       }
       return acclist;
   }
}
 
Hi,

Im new to salesforce, im working on visualforce page to import Account and contacts to salesforce.

here is my requiremnt, please guide me to achive this. 
 
  1. Give the customer ability to import Accounts from external csv file to salesforce with button on custom Visualforce page.
  2. Read the csv file and display the content in the Tabular form in the same Visualforce page.
  3. Verify the Duplicate records based on Phone number, if the phone number of the import record matches with existing Account record then verify for Email field match, if matches then populate error message as Duplicate record on Visualforce page Table under Status column for particular record. Otherwise insert record and update the status column on Visualforce page as Success.
  4. Extend the functionality to multiple Objects (Account, Contact, and Opportunity) from single csv file.
Thanks,
Punith
Im new to salesforce, im working on visualforce page to import Account and contacts to salesforce.

here is my requiremnt, please guide me to achive this. 
 
Give the customer ability to import Accounts from external csv file to salesforce with button on custom Visualforce page.
Read the csv file and display the content in the Tabular form in the same Visualforce page.
Verify the Duplicate records based on Phone number, if the phone number of the import record matches with existing Account record then verify for Email field match, if matches then populate error message as Duplicate record on Visualforce page Table under Status column for particular record. Otherwise insert record and update the status column on Visualforce page as Success.
Extend the functionality to multiple Objects (Account, Contact, and Opportunity) from single csv file.

here is my code: im getting error "common.apex.runtime.impl.ExecutionException: List index out of bounds: 5" and status is not getting updated. 

Please help me

VF:
<apex:page controller="importDataFromCSVController">
    <apex:form >
        <apex:pagemessages />
        <apex:pageBlock >
            <apex:pageBlockSection columns="4">
                  <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
                  <apex:commandButton value="Import Account" action="{!importCSVFile}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock >
           <apex:pageblocktable value="{!accList}" var="acc">
              <apex:column value="{!acc.name}" />
              <apex:column value="{!acc.AccountNumber}" />
              <apex:column value="{!acc.Type}" />
              <apex:column value="{!acc.Accountsource}" />
              <apex:column value="{!acc.Industry }" />
               <apex:column headerValue="Status" >
              <apex:outputText id="status"/>
              </apex:column>
           </apex:pageblocktable>
        </apex:pageBlock>
   </apex:form>
</apex:page>

Apex Class:

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public string csvStatus{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
public string[] csvRecordData;
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++)
           {
               Account accObj = new Account() ;
               csvRecordData = csvFileLines[i].split(',');
               accObj.name = csvRecordData[0] ;            
               accObj.accountnumber = csvRecordData[1];
               accObj.Type = csvRecordData[2];
               accObj.AccountSource = csvRecordData[3];  
               accObj.Industry = csvRecordData[4];
               uploadStatus(accObj);
               csvRecordData[5] = csvStatus;
            }
        insert acclist;
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'error here');
            ApexPages.addMessage(errorMessage);
        } 
  }
  
public List<Account> uploadStatus(Account a)
   {
       for(Account acc:[SELECT Name, Accountnumber FROM Account])
       {
           if(acc.name == a.name && acc.accountnumber == a.accountnumber)
           {
               this.csvStatus = 'Duplicate';
                system.debug('inside if');
           }
           else
           {
               system.debug('inside else');
               acclist.add(a);
               this.csvStatus = 'unique';
               
           }
       }
       return acclist;
   }
}
 
Hi,

Im new to salesforce, im working on visualforce page to import Account and contacts to salesforce.

here is my requiremnt, please guide me to achive this. 
 
  1. Give the customer ability to import Accounts from external csv file to salesforce with button on custom Visualforce page.
  2. Read the csv file and display the content in the Tabular form in the same Visualforce page.
  3. Verify the Duplicate records based on Phone number, if the phone number of the import record matches with existing Account record then verify for Email field match, if matches then populate error message as Duplicate record on Visualforce page Table under Status column for particular record. Otherwise insert record and update the status column on Visualforce page as Success.
  4. Extend the functionality to multiple Objects (Account, Contact, and Opportunity) from single csv file.
Thanks,
Punith