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

Update Account Field with an Account in Opportunity using Apex Trigger
I am using standard Opportunity and I am creating an Account once the Opportunity stage "Closed Won" using a trigger. But after creating the Account I want to update the Account field in the Opportunity with the newly created Account (means I want to link this Opportunity with the newly created Account). Please suggest me as soon as possible how to do this ?
(Very Urgent)
Bellow trigger I have written to create an Account once Opportunity "Closed Own"
trigger UpdateAccount on Opportunity (after insert, after update) {
List <Account> acc = new List <Account>();
for(Opportunity opp : Trigger.new)
{
if(opp.Name!=NULL && opp.AccountId!=NULL && opp.PB_Customer_Group__c=='First Time User' && opp.StageName=='Closed Won')
{
Account acc1=new Account();
acc1.Name=opp.Name;
acc.add(acc1);
}
}
try {
insert acc;
}
catch (system.Dmlexception e) {
system.debug (e);
}
}
(Very Urgent)
Bellow trigger I have written to create an Account once Opportunity "Closed Own"
trigger UpdateAccount on Opportunity (after insert, after update) {
List <Account> acc = new List <Account>();
for(Opportunity opp : Trigger.new)
{
if(opp.Name!=NULL && opp.AccountId!=NULL && opp.PB_Customer_Group__c=='First Time User' && opp.StageName=='Closed Won')
{
Account acc1=new Account();
acc1.Name=opp.Name;
acc.add(acc1);
}
}
try {
insert acc;
}
catch (system.Dmlexception e) {
system.debug (e);
}
}
You can try this code,
This Code is working Fine with your requirement and bulkified also.
Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.
Regards
Suraj