You need to sign in to do that
Don't have an account?
gdk
Getting Error while Uplaoding more than 100 contacts and Accounts
Hi All,
I need to uplaod more than 100 contacts and Accounts like the above CSV file format,
here 2 accounts and 13 contacts iam uploading and also duplicate not allowed for Contacts as well as Account
this is working fine when iam uploading 30 records,
But i am getting following error while uploading more than 30 records
System.LimitException: Too many SOQL queries: 101
below the code i used:
-------------------------------
public PageReference UploadAction() {
Count=0;
contactInsert.clear();
dcontact.clear();
if(csvFile!=null)
{
nameFile=csvFile.toString();
//Read the CSV Rows using split method
filelines = nameFile.split('\n');
}
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Contact cnt= new Contact();
Account Ac=new Account();
List<Account> al= new List<Account>();
cnt.FirstName= inputvalues[0];
cnt.LastName= inputvalues[1];
if(String.isNotBlank(inputvalues[2]))
{
Ac.Name=inputvalues[2];
al=[Select id,Name from Account Where name=:Ac.Name];
if(al.size()==0)
{
insert Ac;
}
List<Account> Acl= new List<Account>();
Acl=[Select id, name from Account Where name=:Ac.Name];
cnt.AccountId=Acl[0].id;
}
cnt.Email= inputvalues[3];
cnt.Phone= inputvalues[4];
List<contact> cl= new List<contact>();
cl=[select id, email from contact where email=:inputvalues[3] and account.name=:inputvalues[2]];
if(cl.size()==0)
{
count++;
contactInsert.add(cnt);
}
else{
cnt.AccountName__C= inputvalues[2];
dcontact.add(cnt);
}
}
if(count!=0)
{
System.Debug('-------------count value----'+ Count);
insert contactInsert;
count=0;
}else{
}
return null;
}
Thanks...!
I need to uplaod more than 100 contacts and Accounts like the above CSV file format,
here 2 accounts and 13 contacts iam uploading and also duplicate not allowed for Contacts as well as Account
this is working fine when iam uploading 30 records,
But i am getting following error while uploading more than 30 records
System.LimitException: Too many SOQL queries: 101
below the code i used:
-------------------------------
public PageReference UploadAction() {
Count=0;
contactInsert.clear();
dcontact.clear();
if(csvFile!=null)
{
nameFile=csvFile.toString();
//Read the CSV Rows using split method
filelines = nameFile.split('\n');
}
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Contact cnt= new Contact();
Account Ac=new Account();
List<Account> al= new List<Account>();
cnt.FirstName= inputvalues[0];
cnt.LastName= inputvalues[1];
if(String.isNotBlank(inputvalues[2]))
{
Ac.Name=inputvalues[2];
al=[Select id,Name from Account Where name=:Ac.Name];
if(al.size()==0)
{
insert Ac;
}
List<Account> Acl= new List<Account>();
Acl=[Select id, name from Account Where name=:Ac.Name];
cnt.AccountId=Acl[0].id;
}
cnt.Email= inputvalues[3];
cnt.Phone= inputvalues[4];
List<contact> cl= new List<contact>();
cl=[select id, email from contact where email=:inputvalues[3] and account.name=:inputvalues[2]];
if(cl.size()==0)
{
count++;
contactInsert.add(cnt);
}
else{
cnt.AccountName__C= inputvalues[2];
dcontact.add(cnt);
}
}
if(count!=0)
{
System.Debug('-------------count value----'+ Count);
insert contactInsert;
count=0;
}else{
}
return null;
}
Thanks...!
Put this query outside of your for loop . Use map instead .
Use belo code.
Let us know if it helps you.
All Answers
You have written the soql in for loop since we are permitted to execute 100 SOQLs in one transaction, please remove it from there or bulkify your code.
Put this query outside of your for loop . Use map instead .
Use belo code.
Let us know if it helps you.
making the above changes we can upload upto 40 Records(Contacts and Accounts), but here i need to upload more than 100 records
Thanks and regards,
What issue you are facing now ?
Thanks..!
below code can you check once
if(csvFile!=null)
{ nameFile=csvFile.toString();
//Read the CSV Rows using split method
filelines = nameFile.split('\n');
}
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
}
Map<Id,Contact> contactMap = new Map<Id,Contact>([select id, email from contact where email=:inputvalues[3] and account.name=:inputvalues[2]]);
-------------------------------------------
it will compare only last record
with out loop how can we compare?