CRM 2011: Win Opportunity using OpportunityClose and WinOpportunityRequest


/ Published in: C#
Save to your folder(s)

How to set opportunity status to WON


Copy this code and paste it in your HTML
  1. private void WinOpportunity(IOrganizationService organizationService, Opportunity opportunity)
  2. {
  3.  
  4. OpportunityClose oppClose = new OpportunityClose
  5. {
  6. OpportunityId = opportunity.ToEntityReference(),
  7. Subject = "Won!",
  8. ActualEnd = DateTime.Now,
  9. Description = "Won!",
  10. };
  11.  
  12. var req = new WinOpportunityRequest
  13. {
  14. OpportunityClose = oppClose,
  15. RequestName = "WinOpportunity",
  16. Status = new OptionSetValue(3)
  17. };
  18.  
  19. var response = (WinOpportunityResponse)organizationService.Execute(req);
  20.  
  21. var results = response.Results;
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.