You need to sign in to do that
Don't have an account?
Rani S 1
Insert failed. First exception on row 0 with id 0039000001rwarYAAQ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
public class AddmultipleContactsController { Contact con = new Contact(); public list<contact> listContacts{ get; set; } public AddmultipleContactsController() { listContacts=new list<Contact>(); listContacts.add(con); } Public void addContacts() { Contact cc = new Contact(); listContacts.add(cc); } public PageReference saveContacts() { for(Integer i=1; i<listContacts.size(); i++) { insert listContacts; } return Page.AllContactssaved; } }
Remove the FOR loop in SaveContacts() method you can directly insert listaccounts in the method, also using DML statements in the loops hits the Governer limits of Salesforce.
If you still find problem, post ur VF page so that ut will be easy to help. Please let me know if it helps you.
Regards,
Onesh.K
All Answers
Remove the FOR loop in SaveContacts() method you can directly insert listaccounts in the method, also using DML statements in the loops hits the Governer limits of Salesforce.
If you still find problem, post ur VF page so that ut will be easy to help. Please let me know if it helps you.
Regards,
Onesh.K
It is working fine by your correction.
But want i need to ask is what do u mean by Governor Limit of Salesforce.
Regards,
Rani
Salesforce Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources. If some Apex code ever exceeds a limit, the associated governor issues a runtime exception that cannot be handled.
Please gothrough the below links.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm
http://resources.docs.salesforce.com/200/16/en-us/sfdc/pdf/salesforce_app_limits_cheatsheet.pdf
Regards,
Onesh.K