An effort to bring a revolution in Salesforce.

Tuesday, 26 July 2016

Read csv file then create Account in Apex Salesforce.

Sample logic code. 



Document doc=[SELECT Body,ContentType,Description,DeveloperName,Name FROM Document WHERE Name = 'Csv File'];
    String[] columns=doc.Body.toString().split('\n');
    String[] columnNames=columns[0].split(',');
    columns.remove(0);

    for(String str:columns)
    {
        Account acc=new Account();
        String[] fields=str.split(',');
        for(Integer i=0;i<fields.size()-1;i++)
        {
            acc.put(columnNames[i],fields[i]);
        }
        lstAccounts.add(acc);
    }


Insert  lstAccounts;
, ,

No comments:

Post a Comment

Get Gmail, Docs, Drive, and Calendar for business