• Rey Chang
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hello All, 

   Newbie to Salesforce and i need help writing a test class - schedule apex + consuming csv file. Below is the code - 
=======================
global class FilePOC_ScheduleClass implements Schedulable {
 
     global Blob csvFileBody;
     global string csvAsString;
    
   global void execute(SchedulableContext sc)
   
    {   
        
        try{
            
            ContentVersion cv=[SELECT id,ContentDocumentId,versiondata
                                    FROM Contentversion
                                   WHERE Id='0990o00000B9TYOA3' ];
        
            csvFileBody =cv.VersionData;
            csvAsString= csvFileBody.toString();
        
            // Logic to split the file contents 
            List<String> csvFileLines= csvAsString.split('\n');
            List<String> newList = new List<String>();
    
            // Logic to remove the fist line - the column name
            for(Integer i=1;i<csvFileLines.size();i++){
                newList.add(csvFileLines[i]);
            }
    
            List<Account> accList = new List<Account>();
            
            for(integer i=0;i<newList.size();i++){
                
                List<String> values = newList[i].split(',');
                
                // Prepare the Account fields for insert
                Account accObj = new Account();
                accObj.Name = values[0];
                accObj.accountnumber = values[1];
                accObj.Type = values[2];
                accObj.AccountSource = values[3];
                accObj.Industry = values[4];
                
                acclist.add(accObj);
            }
            
            // Insert the account collection
            insert acclist;
        }
        catch (Exception e)
        {
            
        }
    }
}
Please help !! 
Thanks 
Rey....
 
Hello All, 

    I am looking at developing a schedule class which can read csv files and insert salesforce records . I am aware of the way , it can be done with the help of a visualforce page, but is there a way in which it can be done without that ? 

Thanks 
Rey
Hello All, 

    Running into problems whilst deleting a custom object. Please help! Attaching the error screenshot ...

User-added image
Regards
Rey
 
Hello All, 

    Running into problems whilst deleting a custom object. Please help! Attaching the error screenshot ...

User-added image
Regards
Rey