[vc_row][vc_column css=”.vc_custom_1485102809783{margin-top: 0px !important;border-top-width: 0px !important;padding-top: 0px !important;}”][vc_wp_text]The following snippet demonstrates how to create a record in C# using the OrganizationServiceContext. The method allows for multiple records to be added to an object before committing to a save.[/vc_wp_text][cq_vc_tabs rotatetabs=”0″][cq_vc_tab_item tabicon=”entypo” icon_entypo=”entypo-icon entypo-icon-code” tabtitle=”Code”]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// The following code creates a Contact record using the OrganizationServiceContext // This method can be used to loop though and add multiple contacts before committing to a single save. try { OrganizationServiceContext orgContext = new OrganizationServiceContext(service); Entity contact = new Entity("contact"); contact["firstname"] = "Pamela"; contact["lastname"] = "Brown"; contact["address1_line1"] = "123 Easy St."; contact["address1_city"] = "Atlanta"; contact["address1_stateorprovince"] = "GA"; contact["address1_postalcode"] = "32254"; contact["telephone1"] = "425-555-5678"; orgContext.AddObject(contact); orgContext.SaveChanges(); } catch (FaultException ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in", ex); } |
[/cq_vc_tab_item][cq_vc_tab_item tabicon=”entypo” icon_entypo=”entypo-icon entypo-icon-info” tabtitle=”Information”][/cq_vc_tab_item][/cq_vc_tabs][vc_wp_text][/vc_wp_text][/vc_column][/vc_row]