You need to sign in to do that
Don't have an account?
santusfdc1.3926196430109492E12
need help with the trigger
Hi members ,
i have written a trigger on the oppportunity in the object if the stage is "closed won " i need to insert a record in the account.and i m getting the error and the error is (Error:Apex trigger opptrigger caused an unexpected exception, contact your administrator: opptrigger: execution of AfterUpdate caused by: System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account Name]: [Account Name]: Trigger.opptrigger: line 23, column 1)
trigger opptrigger on Opportunity (after insert,after update)
{
//Create a list to hold all new records
List<Account> newRecords = new List<Account>();
//Loop around all records in the trigger transaction
for(Opportunity theRecord : Trigger.new)
{
//Evaluate the record against our critieria
if(theRecord.StageName == 'Closed Won')
{
//The line below creates a new Account record and adds it to our list of new records. Add your field assigments (examples below). Make sure to assign all required fields.
Account newRecord = new Account();
//newRecord.Name = theRecord.name;
//newRecord.Description = 'My New Record';
newRecords.add(newRecord);
}
}
//Insert the new records if any exist
if(newRecords.size() > 0)
upsert newRecords;
}
i have written a trigger on the oppportunity in the object if the stage is "closed won " i need to insert a record in the account.and i m getting the error and the error is (Error:Apex trigger opptrigger caused an unexpected exception, contact your administrator: opptrigger: execution of AfterUpdate caused by: System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account Name]: [Account Name]: Trigger.opptrigger: line 23, column 1)
trigger opptrigger on Opportunity (after insert,after update)
{
//Create a list to hold all new records
List<Account> newRecords = new List<Account>();
//Loop around all records in the trigger transaction
for(Opportunity theRecord : Trigger.new)
{
//Evaluate the record against our critieria
if(theRecord.StageName == 'Closed Won')
{
//The line below creates a new Account record and adds it to our list of new records. Add your field assigments (examples below). Make sure to assign all required fields.
Account newRecord = new Account();
//newRecord.Name = theRecord.name;
//newRecord.Description = 'My New Record';
newRecords.add(newRecord);
}
}
//Insert the new records if any exist
if(newRecords.size() > 0)
upsert newRecords;
}
Since This code snippit show that you haven't assigned the required field for Account object. which is name. add newRecord.Name=[value] then everything works fine. hope this will help
All Answers
Since This code snippit show that you haven't assigned the required field for Account object. which is name. add newRecord.Name=[value] then everything works fine. hope this will help
Thanks for your valuable time in solving my issue . and the issue got solved.
Thanks once again. hope you ill be giving me the same assistance in future too.
regards,
Santosh