You need to sign in to do that
Don't have an account?
Sana123
add contacts to only the succesfull account as i am passing two arguments 1 List<Account> and 2 List<contact> in my method. Here is my code
public static void searchForAccount (List<Account>listOfAccount , List<Contact>listOfContact){
// List<Account>listOfAccount = new List<Account>();
// List<Contact>listOfContact = new List<Contact>();
Database.SaveResult[] srList = Database.insert(listOfAccount, false);
for (Database.SaveResult sr : srList) {
if (sr.isSuccess()) {
//listOfContact.add(sr.AccountId);
Database.insert(listOfContact , false);
}
else
{
for(Database.Error err : sr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Contact fields that affected this error: ' + err.getFields());
Error_Log__c a1 = new Error_Log__c(Parent_Record_Name__c = '' , Parent_Record_Id__c = '' ,Error_Details__c = err.getStatusCode() + ': ' + err.getMessage());
database.upsert(a1 , false);
}
}
}
system.debug(listOfContact);
}
}
// List<Account>listOfAccount = new List<Account>();
// List<Contact>listOfContact = new List<Contact>();
Database.SaveResult[] srList = Database.insert(listOfAccount, false);
for (Database.SaveResult sr : srList) {
if (sr.isSuccess()) {
//listOfContact.add(sr.AccountId);
Database.insert(listOfContact , false);
}
else
{
for(Database.Error err : sr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Contact fields that affected this error: ' + err.getFields());
Error_Log__c a1 = new Error_Log__c(Parent_Record_Name__c = '' , Parent_Record_Id__c = '' ,Error_Details__c = err.getStatusCode() + ': ' + err.getMessage());
database.upsert(a1 , false);
}
}
}
system.debug(listOfContact);
}
}
It seems your question is not clear, Please frame it more clarity .
Thanks!
if (sr.isSuccess()) {
//listOfContact.add(sr.AccountId);
Database.insert(listOfContact , false);
}
else
{
for(Database.Error err : sr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Contact fields that affected this error: ' + err.getFields());
Error_Log__c a1 = new Error_Log__c(Parent_Record_Name__c = '' , Parent_Record_Id__c = '' ,Error_Details__c = err.getStatusCode() + ': ' + err.getMessage());
database.upsert(a1 , false);
but the problem which i am facing is that i have to add contact to only those account which are going to success ..how can i add the contacts by passing the contact and account as a argument..
Kindly help me in this