public with sharing class AccountHandler {
public static void CreateNewOpportunity(List<Account> accts) {
for (Account a : accts) {
Opportunity opp = new Opportunity();
opp.Name = a.Name + 'Opportunity';
opp.AccountId = a.Id;
opp.StageName = 'Prospecting';
opp.CloseDate = System.Today().addMonths(1);
insert opp;
}
}
}
Hi, I am new to Salesforce... I am trying to follow this Module, https://trailhead.salesforce.com/modules/apex_basics_dotnet/units/execution_context but it throws duplicate error when i execute from Execute anonymous method. Line: 6, Column: 1 System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: []
I want to post in Apex community but it says it already exists and gives me id number which do not match my question at all and i could not post a new question. Any help is appreciated.
trigger AccountTrigger on Account (before insert, before update, before
delete, after insert, after update, after delete, after undelete) {
if (Trigger.isAfter && Trigger.isInsert) {
AccountHandler.CreateNewOpportunity(Trigger.New);
}
}
If this does not work, I would suggest you try in new trailhead playgrouns as there may be pre existing configuration that is stopping you to check challenge.
Please mark it as solved if my reply was helpful, it will make it available for others as a proper solution.
Hi, I am new to Salesforce... I am trying to follow this Module, https://trailhead.salesforce.com/modules/apex_basics_dotnet/units/execution_context but it throws duplicate error when i execute from Execute anonymous method.
Line: 6, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, Use one of these records?: []
I want to post in Apex community but it says it already exists and gives me id number which do not match my question at all and i could not post a new question. Any help is appreciated.
Below is the code which worked for me
https://developer.salesforce.com/forums/?id=906F0000000DBRhIAO
If this does not work, I would suggest you try in new trailhead playgrouns as there may be pre existing configuration that is stopping you to check challenge.
Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.
Best Regards,
Sandhya