You need to sign in to do that
Don't have an account?
ShayKhan
Hello All, New to the Salesforce development community and have a requirement that i need some help with!
Im fairly new to Apex, so this question may seem mediocre but i've really just hit a wall at this point.
Below is the requirement:
Insert 2 accounts with type = 'Prospect'
Insert 2 contacts - 1 contact Lead source = 'Phone Enquiry' - Relate to 1 account
- 2 Contact Lead Sorce ='Partner Referal' - Relate to 2 account
CHeck if(Contact Lead source = Phone Enquiry)
Related Account type = "Installation Partner";
Below is the what i have so far:
Below is the requirement:
Insert 2 accounts with type = 'Prospect'
Insert 2 contacts - 1 contact Lead source = 'Phone Enquiry' - Relate to 1 account
- 2 Contact Lead Sorce ='Partner Referal' - Relate to 2 account
CHeck if(Contact Lead source = Phone Enquiry)
Related Account type = "Installation Partner";
Below is the what i have so far:
public class AccountnContactClass{ //Create 2 account and 2 Contacts using List and Limiting the Insert DML statements public void AccountContactCreation(){ List<Account> AccList = new list <Account>(); Account ac8 = New Account(); ac8.Name = 'Apples'; ac8.type = 'prospect'; Account ac9 = New Account(); ac9.Name = 'Oranges'; ac9.type = 'prospect'; AccList.add(ac8); AccList.add(ac9); Insert AccList; List<contact> ContactList = new list <contact>(); Contact Con1 = New Contact(); Con1.FirstName = 'Tomatoes'; Con1.LastName = 'Rotten'; Con1.LeadSource = 'Phone Inquiry'; Con1.accountid = Acclist[0].id; Contact Con2 = New Contact(); Con2.FirstName = 'G2'; Con2.LastName = 'Gatorade'; Con2.LeadSource = 'Partner Referral'; //Con2.accoundid = AccList[1].id; ContactList.add(Con1); ContactList.add(Con2); Insert ContactList; } }
Account a=new Account(Name='po');
insert a;
Contact c=new Contact(Lastname='op');
c.accountid=a.id;
insert c;
Contact d=[select Account.name from Contact where accountid=:a.id Limit 1];
d.account.type='Installation Partner';
update d.account;
All Answers
Sateesh, the code works fine upto inserting both the account and contact list it's the last part of the requirement I am stuck on. I just need to see how UPDATE works As the examples in the documentations were a bit confusing for me.
Account a=new Account(Name='po');
insert a;
Contact c=new Contact(Lastname='op');
c.accountid=a.id;
insert c;
Contact d=[select Account.name from Contact where accountid=:a.id Limit 1];
d.account.type='Installation Partner';
update d.account;
I was able to fulfill the requirement using the example you provided A++++ for you!