You need to sign in to do that
Don't have an account?

trigger code
Hi
I need help in writing a trigger for the below apex class.
when I create a new account, an opportunity record is created.
Public class OpporInsertAfterAccount
{
public void Display(List<Account> accounts)
{
List<Opportunity> listOpportunities = new List<Opportunity>();
for(Account oAccount:accounts)
{
Opportunity oOpportunity = new Opportunity();
oOpportunity.Name = oAccount.Name;
oOpportunity.AccountId = oAccount.Id;
oOpportunity.StageName = 'Qualification';
oOpportunity.CloseDate = System.today() + 30; //Closes 30 days from today
listOpportunities.add(oOpportunity);
}
if (listOpportunities.isEmpty() == false)
{
Database.insert(listOpportunities);
}
}
}
Thanks
sonali
I need help in writing a trigger for the below apex class.
when I create a new account, an opportunity record is created.
Public class OpporInsertAfterAccount
{
public void Display(List<Account> accounts)
{
List<Opportunity> listOpportunities = new List<Opportunity>();
for(Account oAccount:accounts)
{
Opportunity oOpportunity = new Opportunity();
oOpportunity.Name = oAccount.Name;
oOpportunity.AccountId = oAccount.Id;
oOpportunity.StageName = 'Qualification';
oOpportunity.CloseDate = System.today() + 30; //Closes 30 days from today
listOpportunities.add(oOpportunity);
}
if (listOpportunities.isEmpty() == false)
{
Database.insert(listOpportunities);
}
}
}
Thanks
sonali
1. Write trigger in Account Object.
2. Use the below code and pass the Trigger.new value to the class that you have created.
trigger AccountTrigger on Account(after insert)
{
OpporInsertAfterAccount oa = new OpporInsertAfterAccount();
oa.Display(Trigger.new);
}