Technology has always been a bridge, but today, it feels more like a mirror. With the rapid rise of AI , we are seeing things enter our lives and leave them at a pace we can barely track. To understand where this is going, we first have to understand how technology actually impacts the core of who we are. The Survivalist vs. The Ego Our minds are biologically wired for one thing: survival . We are designed to handle the worst-case scenario, an ancient instinct gifted to us by nature. We consider ourselves conscious decision-makers, but a critical question remains: Who is really making the call?
Here is sample code to upload CSV file and insert CSV data in salesforce objects.
In this Code we are inserting data in contact object using standard template. First Column of CSV is Name, second column is LastName and third one is Title.
Visualforce Page
<apex:page controller="ReadandInsertController">
<apex:form >
<apex:pagemessages />
<apex:pageBlock >
<apex:actionRegion >
<apex:inputFile value="{!UploadedFileContent}" filename="{!FileName}" />
<apex:commandButton action="{!UploadRecords}" value="Upload File"/>
</apex:actionRegion>
<apex:pageblocktable value="{!uploadedContact}" id="Contable" var="con">
<apex:column headerValue="Name">
<apex:outputText value="{!con.FirstName }"/>
</apex:column>
<apex:column headerValue="LastName">
<apex:outputText value="{!con.lastName }"/>
</apex:column>
<apex:column headerValue="Title">
<apex:outputText value="{!con.Email}"/>
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class
public class ReadandInsertController {
public string FileName{get;set;}
public Blob UploadedFileContent{get;set;}
List<string> fileRows;
public List<Contact > Contoupload {get;set;}
public Pagereference UploadRecords(){
fileRows = new list<string>();
FileName=UploadedFileContent.tostring();
fileRows = FileName.split('\n');
Contoupload = new List<Contact >();
for (Integer i=1;i<fileRows .size();i++){
String[] CSV = new String[]{};
CSV = fileRows [i].split(',');
Contact con = new Contact ();
con .FirstName = CSV [0];
con.LastName=CSV [1];
con.email=CSV [2];
Contoupload.add(con);
}
insert Contoupload;
return null;
}
public List<Contact > getuploadedContact(){
if (Contoupload!= NULL){
if (Contoupload.size() > 0){
return Contoupload;
}else{
return null;
}
}else{
return null;
}
}
}
| Read CSV and insert CSV records in salesforce |
Visualforce Page
<apex:page controller="ReadandInsertController">
<apex:form >
<apex:pagemessages />
<apex:pageBlock >
<apex:actionRegion >
<apex:inputFile value="{!UploadedFileContent}" filename="{!FileName}" />
<apex:commandButton action="{!UploadRecords}" value="Upload File"/>
</apex:actionRegion>
<apex:pageblocktable value="{!uploadedContact}" id="Contable" var="con">
<apex:column headerValue="Name">
<apex:outputText value="{!con.FirstName }"/>
</apex:column>
<apex:column headerValue="LastName">
<apex:outputText value="{!con.lastName }"/>
</apex:column>
<apex:column headerValue="Title">
<apex:outputText value="{!con.Email}"/>
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class
public class ReadandInsertController {
public string FileName{get;set;}
public Blob UploadedFileContent{get;set;}
List<string> fileRows;
public List<Contact > Contoupload {get;set;}
public Pagereference UploadRecords(){
fileRows = new list<string>();
FileName=UploadedFileContent.tostring();
fileRows = FileName.split('\n');
Contoupload = new List<Contact >();
for (Integer i=1;i<fileRows .size();i++){
String[] CSV = new String[]{};
CSV = fileRows [i].split(',');
Contact con = new Contact ();
con .FirstName = CSV [0];
con.LastName=CSV [1];
con.email=CSV [2];
Contoupload.add(con);
}
insert Contoupload;
return null;
}
public List<Contact > getuploadedContact(){
if (Contoupload!= NULL){
if (Contoupload.size() > 0){
return Contoupload;
}else{
return null;
}
}else{
return null;
}
}
}