while i am uploading from csv file i need to create account and contact i have achieved this using apex code. i need to check whether the account name already exist or not. Whether i need to write apex trigger for this. kindly give me any idea to solve this. i am not using Dataloader i need to do this using programming.
code:
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Account>();
contoupload = new List<Contact>();
opptoupload = new List<Opportunity>();
custtoupload = new List<CustomLead__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Account a = new Account();
a.Name = inputvalues[0];
accstoupload.add(a);
}
try
{
insert accstoupload;
}
catch (Exception e) {
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
ApexPages.addMessage(errormsg);
}