You need to sign in to do that
Don't have an account?
How to use inserted account returned list record for contact insertion
Hi All,
in the below code i am creating account record which is returning inserted record in list form accountList. now i want to use the account id created in contact record insertion. so please can you let me know how can i use as i want to pass inserted account id to contact as parameter .
public class AccountTest
{
public static List<Account> CreateAccount()
{
List<Account> accountList = new List<Account>();
Account Acc=new Account(Name='Test2');
accountList.add(acc);
insert accountList;
return accountList;
}
public static List<Contact> CreateContact(account accid)
{
List<Contact> contactList=new List<Contact>();
Contact con=new Contact(Lastname='Test1',
AccountId=accid.id);
contactList.add(con);
insert contactList;
return contactList;
}
}
in the below code i am creating account record which is returning inserted record in list form accountList. now i want to use the account id created in contact record insertion. so please can you let me know how can i use as i want to pass inserted account id to contact as parameter .
public class AccountTest
{
public static List<Account> CreateAccount()
{
List<Account> accountList = new List<Account>();
Account Acc=new Account(Name='Test2');
accountList.add(acc);
insert accountList;
return accountList;
}
public static List<Contact> CreateContact(account accid)
{
List<Contact> contactList=new List<Contact>();
Contact con=new Contact(Lastname='Test1',
AccountId=accid.id);
contactList.add(con);
insert contactList;
return contactList;
}
}
public class AccountTest
{
public static List<Account> CreateAccount()
{
List<Account> accountList = new List<Account>();
Account Acc=new Account(Name='Test2');
accountList.add(acc);
insert accountList;
return accountList;
}
public static List<Contact> CreateContact(account accid)
{
List<Account> accList = CreateAccount();
List<Contact> contactList=new List<Contact>();
Contact con=new Contact(Lastname='Test1',
con.AccountId = accList[0].id;
contactList.add(con);
insert contactList;
return contactList;
}
}
like below
public class AccountTest
{
public static List<Account> CreateAccount(List<Account>fieldmapvalue)
{
List<Account> accountList = new List<Account>();
Account Acc=new Account(Name='Test2');
accountList.add(acc);
insert accountList;
return accountList;
}
}
public class ContactTest
{
public static List<Contact> CreateContact(List<Contact>fieldvaluemap,account accid)
{
List<Account> accList = CreateAccount();
List<Contact> contactList=new List<Contact>();
Contact con=new Contact(Lastname='Test1',
con.AccountId = accList[0].id;
contactList.add(con);
insert contactList;
return contactList;
}
}
now in this case i want to use accountid in contact insertion so please can you suggest
I had a similar scenario and modified your code accordingly. But no idea why you are using Static.
Please find below code.
Class AccountTest:
Class ContactTest: I have tested the code by calling CreateAcontact method and it works fine.
Let me know if that works for you or any modifications required.
Best Regards,
BALAJI