• krishna jammigumpula
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
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();
           system.debug(csvAsString);
              String[] csvFileLines = new String[]{};
              if(csvFileLines.size()==1 ){
                  csvFileLines = csvAsString.split('\n'); 
                system.debug(csvFileLines);
               for(Integer i=1;i<csvFileLines.size();i++){
               system.debug(i);
               Account accObj = new Account() ;
               string[] csvRecordData = csvFileLines[i].split(',');
               system.debug(csvRecordData);    
               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  ){
                      acclist.add(accObj);   
                  }
                    try{ 
                        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());
            ApexPages.addMessage(errorMessage);
        }               
        
     }     
}
        
  }
}

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}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
   </apex:form>
</apex:page>


any help will be apriciate
Thanks in advance