{"id":388,"date":"2010-11-02T00:13:38","date_gmt":"2010-11-02T00:13:38","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=388"},"modified":"2010-11-02T00:13:38","modified_gmt":"2010-11-02T00:13:38","slug":"create-opportunity-relationship-record","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=388","title":{"rendered":"Create Opportunity Relationship record"},"content":{"rendered":"<p>Sometime we need to create \u201cOpportunity Relationship\u201d record through code. We can use below code to create Opportunity relationship record. Basically we need to set three values while creating opportunity relationship record customerid, opportunityid and opportunityroleid.<\/p>\n<p>\/\/I have used Dynamic entity to create opportunity relationship record<\/p>\n<p>DynamicEntity\u00a0 _OpportunityRelationship = new DynamicEntity();<\/p>\n<p>\/\/Set entity name as \u201ccustomeropportunityrole\u201d\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>\u00a0_OpportunityRelationship.Name = &#8220;customeropportunityrole&#8221;;<\/p>\n<p>\/\/Create property to set customer\u00a0<\/p>\n<p>CustomerProperty _OpportunityCustomer=new CustomerProperty();<\/p>\n<p>\u00a0\u00a0_ OpportunityCustomer.Name=&#8221;customerid&#8221;;<\/p>\n<p>\u00a0_ OpportunityCustomer.Value=new Customer();<\/p>\n<p>\u00a0_ OpportunityCustomer.Value.type = &#8220;account&#8221;; \/\/Set customer type (I am using account here)<\/p>\n<p>\u00a0_ OpportunityCustomer.Value.Value=CustomerGUID;\u00a0 \/\/replace CustomerGUID with customer GUID<\/p>\n<p>_OpportunityRelationship.Properties.Add(_OpportunityCustomer);<\/p>\n<p>\/\/set Opportunity ID\u00a0<\/p>\n<p>LookupProperty _OpportunityID=new LookupProperty();<\/p>\n<p>\u00a0_ OpportunityID.Name=&#8221;opportunityid&#8221;;<\/p>\n<p>\u00a0_ OpportunityID.Value=new Lookup();<\/p>\n<p>\u00a0_ OpportunityID.Value.Value=OpportunityID; \/\/replace OpportunityID with opportunity GUID<\/p>\n<p>\u00a0_OpportunityRelationship.Properties.Add(_OpportunityID);<\/p>\n<p>\u00a0\/\/Set Opportunity Role<\/p>\n<p>\/\/you can create Relationship Roles from Setting-&gt;Business Management-&gt;Relationship Roles\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>\u00a0LookupProperty _OpportunityRole = new LookupProperty();<\/p>\n<p>\u00a0_OpportunityRole.Name = &#8220;opportunityroleid&#8221;;<\/p>\n<p>\u00a0_OpportunityRole.Value = new Lookup();<\/p>\n<p>\u00a0\u00a0 _OpportunityRole.Value.Value =GUIDofRelationshipRole; \/\/Replace GUIDofRelationshipRole with Relationship role Guid.<\/p>\n<p>\u00a0\u00a0 _OpportunityRelationship.Properties.Add(_OpportunityRole);<\/p>\n<p>\u00a0 TargetCreateDynamic targetCreate = new TargetCreateDynamic();<\/p>\n<p>\u00a0 targetCreate.Entity = _OpportunityRelationship;<\/p>\n<p>\/\/ Create the request object.<\/p>\n<p>\u00a0CreateRequest create = new CreateRequest();<\/p>\n<p>\u00a0 \/\/ Set the properties of the request object.<\/p>\n<p>\u00a0 create.Target = targetCreate;<\/p>\n<p>\u00a0\/\/ Execute the request.<\/p>\n<p>\u00a0CreateResponse created = (CreateResponse)_Service.Execute(create);<\/p>\n<p>\u00a0Hope it will help somebody.<\/p>\n<p>Cheer \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometime we need to create \u201cOpportunity Relationship\u201d record through code. We can use below code to create Opportunity relationship record. Basically we need to set three values while creating opportunity relationship record customerid, opportunityid and opportunityroleid. \/\/I have used Dynamic entity to create opportunity relationship record DynamicEntity\u00a0 _OpportunityRelationship = new DynamicEntity(); \/\/Set entity name as \u201ccustomeropportunityrole\u201d\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0_OpportunityRelationship.Name = &#8220;customeropportunityrole&#8221;; \/\/Create&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=388\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,20],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/388"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=388"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/388\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}