You need to sign in to do that
Don't have an account?
Prema -
Hello Friends could you please help me to update the id of Opportunity's description with opportunity id inside trigger
trigger CreateOpportunityRelatedAccount on Opportunity (before insert) { public string ids; List<Opportunity> oppLstToUpdate=new List<Opportunity>(); if(Trigger.isInsert) { for(Opportunity opp : Trigger.new) { oppLstToUpdate.add(opp); ids=opp.id; opp.Description=ids; } } }
We don't have id on before insert so we need to fire the trigger on after insert.
Please refer to the code.
trigger CreateOpportunityRelatedAccount on Opportunity (after insert)
{
List<Opportunity> oppLstToUpdate=new List<Opportunity>();
if(Trigger.isInsert)
{
for(Opportunity opp : Trigger.new)
{
Opportunity opp1 = new Opportunity();
opp1.Id = opp.Id;
opp1.Description=opp1.Id;
oppLstToUpdate.add(opp1);
}
}
Database.update(oppLstToUpdate,false);
}
Thank you
Ajay Dubedi
All Answers
So you have to use after insert here.
Refer below code:-
We don't have id on before insert so we need to fire the trigger on after insert.
Please refer to the code.
trigger CreateOpportunityRelatedAccount on Opportunity (after insert)
{
List<Opportunity> oppLstToUpdate=new List<Opportunity>();
if(Trigger.isInsert)
{
for(Opportunity opp : Trigger.new)
{
Opportunity opp1 = new Opportunity();
opp1.Id = opp.Id;
opp1.Description=opp1.Id;
oppLstToUpdate.add(opp1);
}
}
Database.update(oppLstToUpdate,false);
}
Thank you
Ajay Dubedi
for(Opportunity opp : Trigger.new)
{
Opportunity opp1 = new Opportunity();
opp1.Id = opp.Id;
opp1.Description=opp1.Id;
oppLstToUpdate.add(opp1);
}
}
Database.update(oppLstToUpdate,false);
In this instance, you'll need to clone the record (or query anew via SOQL) and make changes to the new copy of the record, then execute the update against the new copies.