Last name is mandetory field in salesforce ..so you should take input for last name in visualforce page..like <apex:inputField value="{!con.lastname}"/>
Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
public with sharing class ApexClassHomeWork { public List<Account> accs {get; set;}
// retrieves the list of accounts backing the page public ApexClassHomeWork() { accs=[select id, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name LIKE 'Test%' LIMIT 10]; }
public void createContact(Id acctId) { for(Integer i=0; i<500; i++) { Contact c = new Contact(AccountId=acctId, "last name"); insert c; } } }
public class Contact P public contact(ID.AccountID) throw LastNameException if lastName.isEmpty {
<apex:inputField value="{!con.lastname}"/>
Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
{
public List<Account> accs {get; set;}
// retrieves the list of accounts backing the page
public ApexClassHomeWork()
{
accs=[select id, Name, BillingStreet, BillingCity, BillingPostalCode FROM Account WHERE Name LIKE 'Test%' LIMIT 10];
}
public void createContact(Id acctId)
{
for(Integer i=0; i<500; i++)
{
Contact c = new Contact(AccountId=acctId, "last name");
insert c;
}
}
}
public class Contact P
public contact(ID.AccountID) throw LastNameException
if lastName.isEmpty {
throw LastNameException
I have tested my code, Please use this code your side:-
Please MARK AS A BEST ANSWER!!!!
REgards
Mukesh
accs=[select id FROM Account where name like 'Test%'];
for(Account a:accs){
a.id=accs[0].id;
Contact c = new Contact();
c.AccountID = a.id;
c.FirstName='UJWALA';
c.LastName='MANE';
insert c;