You need to sign in to do that
Don't have an account?
Vishnuvardhan Reddy 14
Need to create 2 different stage opportunities for an Account creation
Hi All,
Below is my code snippet but it is not working..
trigger Acc_Opty_Creation on Account (after insert) {
List <Account> accList = Trigger.New;
User u= [Select id from user where alias ='integ'];
List<Opportunity> opty= New List<Opportunity>();
List<Opportunity> opty2= New List <Opportunity>();
for (Account a : accList){
Opportunity op = new Opportunity();
op.Name= a.Name+'_Opty';
op.CloseDate=System.today()+15;
op.StageName='Prospecting';
op.AccountId= a.Id;
op.OwnerId=u.Id;
opty.add(op);
}
insert opty;
for (Account a : accList){
Opportunity Op2 = new Opportunity();
op2.Name= a.Name+'_Opty';
op2.CloseDate=System.today()+20;
op2.StageName='Needs Analysis';
op2.AccountId= a.Id;
op2.OwnerId=u.Id;
opty2.add(op2);
}
insert opty2;
}
Below is my code snippet but it is not working..
trigger Acc_Opty_Creation on Account (after insert) {
List <Account> accList = Trigger.New;
User u= [Select id from user where alias ='integ'];
List<Opportunity> opty= New List<Opportunity>();
List<Opportunity> opty2= New List <Opportunity>();
for (Account a : accList){
Opportunity op = new Opportunity();
op.Name= a.Name+'_Opty';
op.CloseDate=System.today()+15;
op.StageName='Prospecting';
op.AccountId= a.Id;
op.OwnerId=u.Id;
opty.add(op);
}
insert opty;
for (Account a : accList){
Opportunity Op2 = new Opportunity();
op2.Name= a.Name+'_Opty';
op2.CloseDate=System.today()+20;
op2.StageName='Needs Analysis';
op2.AccountId= a.Id;
op2.OwnerId=u.Id;
opty2.add(op2);
}
insert opty2;
}
try this code and please let me know if it helps and mark it as best answer..
List<Opportunity> optyList=new List<Opportunity>();
for(Account a:Trigger.new)
{
integer i = 0;
Opportunity opp = new Opportunity();
opp.AccountId=a.id;
opp.Name='Created from account'+ i++;
opp.StageName='Prospecting';
opp.LeadSource = 'Web';
opp.CloseDate=Date.toDay();
optyList.add(opp);
Opportunity opp1 = new Opportunity();
opp1.AccountId=a.id;
opp1.Name='Created from account' +i++;
opp1.StageName='Closed Won';
opp1.LeadSource = 'Other';
opp1.CloseDate=Date.toDay();
optyList.add(opp1);
}
insert optyList;