You need to sign in to do that
Don't have an account?
Preethi S
Create Opportunity record
Hi all,
I have to create one Opportunity record.When I create that record the another record will be created automatically by using triggers.
This is my code. this is not working properly. It shows null pointer exception...Can u tell about this?
trigger OpprtunityInsertion on Opportunity (after insert) {
List<Opportunity> listOfOpportunities = new List<Opportunity>();
for(Opportunity op : Trigger.new)
{
if(op.StageName == 'Closed Won')
{
Opportunity o= new Opportunity();
o.Name = 'Cloned'+op.Name;
o.StageName=op.StageName+'Cloned';
o.CloseDate=op.CloseDate.addYears(1);
listOfOpportunities.add(o);
}
}
insert listOfOpportunities;
}
I have to create one Opportunity record.When I create that record the another record will be created automatically by using triggers.
This is my code. this is not working properly. It shows null pointer exception...Can u tell about this?
trigger OpprtunityInsertion on Opportunity (after insert) {
List<Opportunity> listOfOpportunities = new List<Opportunity>();
for(Opportunity op : Trigger.new)
{
if(op.StageName == 'Closed Won')
{
Opportunity o= new Opportunity();
o.Name = 'Cloned'+op.Name;
o.StageName=op.StageName+'Cloned';
o.CloseDate=op.CloseDate.addYears(1);
listOfOpportunities.add(o);
}
}
insert listOfOpportunities;
}
Code you have posted will work fine. Please check your trigger whether you are using trigger.old
trigger OpprtunityInsertion on Opportunity (after insert) {
List<Opportunity> listOfOpportunities = new List<Opportunity>();
for(Opportunity op : Trigger.new)
{
if(op.StageName == 'Closed Won')
{
Opportunity o= new Opportunity();
o.Name = 'Cloned'+op.Name;
o.StageName=op.StageName+'Cloned';
o.CloseDate=op.CloseDate.addYears(1);
listOfOpportunities.add(o);
}
}
insert listOfOpportunities;
}
Mark this as solution if you got an answer
Thanks.
Praveen Murugesan
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AW5B
yes I am doing some tasks in triggers...