Friday, April 16, 2010

Adding Opportunities In MS CRM with Code!

Ok, in case anyone cares, I am now doing a LOT of custom dev with MS CRM 4.0. If you have a question, ask me. I have probably already done it!

Anyway, I'll try and share code snippets when I think about it. Here is how to create a new opportunity via code. You know, in case you have a dataset of leads and want to auto-magically create opportunities from it.

opportunity o = new opportunity();
o.name = "*NAME OF OPP*";
Customer c = new Customer();
c.type = EntityName.account.ToString();
c.Value = new Guid(*GUID of Account to tie it to*);
o.customerid = c;
//ADD any other data about the opp HERE!!
//Grab the new opportunities ID on create!
Guid gOpId = _Service.Create(o);

See? Easy!

No comments: