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

error with code only works on one transaction at a time
i have a problem , when testing this code by inserting more than 2 records via dataloader i get below error: i had only ever been testing by manually adding 1 contact at a time.......i understand i may have to move the DML outside of the loop but i am new to apex and not sure how to fix this
easycontacttrigger: execution of AfterInsert
caused by: System.DmlException: Insert failed. First exception on row 0 with id a13250000005OnzAAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Class.easycontacttriggerhelper.buyerconConveyancy2: line 139, column 1
Trigger.easycontacttrigger: line 28, column 1
here's a snippet of the class
easycontacttrigger: execution of AfterInsert
caused by: System.DmlException: Insert failed. First exception on row 0 with id a13250000005OnzAAE; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Class.easycontacttriggerhelper.buyerconConveyancy2: line 139, column 1
Trigger.easycontacttrigger: line 28, column 1
here's a snippet of the class
public with sharing class easycontacttriggerhelper { public static void buyerconConveyancy2(list<Contact> cons) { system.debug('###list<Contact> cons ' + cons); list<Easy_Opportunity__c> opplist = new list <Easy_Opportunity__c>(); recordtype[] tt = [Select r.Id, r.SobjectType, r.Name From RecordType r where sobjecttype ='Easy_Opportunity__c' and Name = 'Residential Sales']; for(Contact con : cons){ system.debug('### con ' + con); if( con.Stage__c == 'Lead' && con.contacttype__c != null && con.contacttype__C.contains('Buyer')){ Easy_Opportunity__c newopp = new Easy_Opportunity__c (); newopp.ownerid = con.Allocated_Negotiator__c; newopp.name = 'Applicant Conveyancy Opportunity'; newopp.account_name__c = con.accountid; newopp.CurrencyIsoCode = con.currencyisocode; newopp.stage__c = 'New'; newopp.recordtypeid = tt[0].Id; newopp.Contact_Name__c = con.id; newopp.Close_Date__c = Date.today().addDays(2); opplist.add(newopp); insert opplist; system.debug('### opplist ' + opplist); List<Product__c> Pd = (List<Product__c>) System.Json.deserialize('[{"attributes":{"type":"Product__c"},"Name":"Conveyancing","Sale_Price__c":"111.00"}]', List<Product__c>.class); for (Product__c eachProd : Pd) eachProd.Easy_Opportunity__c = opplist[0].id; insert Pd; system.debug('### pd ' + pd); } } } }
NOTE: This code has not been tested and may contain typographical or logical errors
List<Product__c> prodList = (List<Product__c>) System.Json.deserialize('[{"attributes":{"type":"Product__c"},"Name":"Conveyancing","Sale_Price__c":"111.00"}]', List<Pro
duct__c>.class);
yes i see that but it pasted ok into one line.........is this error because its a master-detail relationship?