• krishna jammigumpula
  • 0 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 0
I want to display or update  pic  awhen ever i want Example in linekedin there is profilepic where we can change our pic when ever we want like wase i want to update in community using lighting component

#Thanks in advance
scenario 1) whie uploading csv i want to check is it has data or not if data is not having i want throw error
scenario 2) whie uploading csv i want to check is it has data  if any column not having i want throw error

For this i have written below code

Apex class
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
  public void importCSVFile(){
           List<account> acclist = New List<Account>();       
           string csvAsString = csvFileBody.toString();
              String[] csvFileLines = new String[]{};
              if(csvFileLines.size()==1 ){
                  csvFileLines = csvAsString.split('\n'); 
               for(Integer i=1;i<csvFileLines.size();i++){
               Account accObj = new Account() ;
               string[] csvRecordData = csvFileLines[i].split(',');
               accObj.name = csvRecordData[0] ;     
               accObj.accountnumber = csvRecordData[1];
               accObj.Type = csvRecordData[2];
               accObj.AccountSource = csvRecordData[3];   
               accObj.Industry = csvRecordData[4];     
               if(accObj.name !=null && accObj.accountnumber !=null &&  accObj.Type  !=null && accObj.AccountSource!=null && accObj.Industry!=null  ){
                        insert acclist;
                   ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Quote Source/s inserted successfully'));
               }    catch (Exception e){
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importing data Please make sure input csv file is correct :'+e.getMessage());

Visual force page
<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}"/>

any help will be apriciate
Thanks in advance