You need to sign in to do that
Don't have an account?

Code to convert an Opportunity into a Contract - difficult?
Hello,
Being a business that provides services, I need a third stage of the Salesforce process for when we have won the contract a the end of the Opportunity phase. This will be for the period where we have won a contract for some business, and it would be great to have Salesforce workflow etc to ensure that we provide what we promised to provide to our customers.
It appears to me that Contracts would be the perfect tool, however there is apparently no way of transferring information such as quotations, sales notes, company names or contacts directly from a Salesforce Opportunity into a Salesforce Contract.
The people at Salesforce say this ought to be possible with some fairly simple Apex code, but I don't know where to start.
This was clearly an issue back in 2010 - see http://boards.developerforce.com/t5/General-Development/New-to-Sales-force-Convert-Opportunity-to-Contract/td-p/163183 .Annoyingly, the link to the supposed "answer" no longer works.
Please help!
Best regards,
Alex.
Try this code.. If solved mark it as answer, so that it can be useful to others
All Answers
Alex, from this and some of your earlier posts I would nicely recommend learning some basic Apex, SOQL and declarative development on our platform. A great place to start would be here http://www.salesforce.com/us/developer/docs/workbook/index.htm. I would also recommend reading these two blog posts: http://blogs.developerforce.com/developer-relations/2013/07/five-essentials-for-new-salesforce-platform-developers.html and http://blogs.developerforce.com/developer-relations/2013/06/advice-for-developers-new-to-the-salesforce-platform.html. Welcome to the platform, looking forward to seeing you around the community.
Dear Ryan,
Thanks very much for your post. It's a great medium term solution and one which I shall certainly be following - I have made plans for this weekend involving the links you kindly provided. My problem today is that there is no way I will learn enough by next week, when I need to have a solution in place.
Other people have clearly had this problem before, so what I'm hoping is that someone will be able to share with me some code that I can adapt. The Salesforce developers have promised to help me if I can give them something to start with.
Any offer of code that does something similar would be gratefully considered.
Best regards,
Alex.
Try this code.. If solved mark it as answer, so that it can be useful to others
Dear Hussein,
Thank you very much for this - will check out and come back to you shortly.
Best regards,
Alex.
Dear Hussein,
Thank you again for this code. Absolutely first class! I have also learned a lot in the process - maybe in a few months I'll be writing my first proper code.
I'm going to post another topic requesting a slight modification - I need to be able to transfer the custom fields we have written in our opportunities overt to the contracts. Hope very much you will be able to take a look.
Best regards,
Alex.
I have used your code which is perfectly working, Many thanks.
Personaly i would go deeper and looking to link the fresh created Contract to the Opportunity who fired the trigger.
i have just add the following lines into you code, but seems to be not so easy : could you help please ?
thank you