function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Installing my first piece of Apex code

Someone I met on these boards has kindly helped me write a piece of code that should create a contract from an opportunity, and copy over our custom fields (see below).


I am now struggling with the task of getting it deployed into our org.  We have enterprise edition - is there anyone who would be prepared to walk me through what I need to do, stage by stage?


Please, please help!



trigger CreatecontractonOppstageclosewon on Opportunity (after insert , after update) {
Set<Id> accId = new Set<Id>();
List<Opportunity> opplist = new List<Opportunity>();
List<contract> conrtlist = new List<contract>();
for(Opportunity opp :{
if(opp.StageName == 'Closed Won'){
Contract con = new Contract();
if(opp.AccountId != NULL){
con .AccountId = opp.AccountId;
con .Status = 'Draft';
con .StartDate = System.Today();
con .ContractTerm = 6;
con.X3_RESEARCH_site_history__c) - opp.X3_RESEARCH_site_history__c)
con.X4_RESEARCH_likely_issues__c = opp.X4_RESEARCH_likely_issues__c
con.X5_RESEARCH_Stakeholders__c - opp.X5_RESEARCH_Stakeholders__c
con.X6_RESEARCH_company_other_projects__c = opp.X6_RESEARCH_company_other_projects__c
con.Client_Code__c = opp.Client_Code__c
con.Council__c = opp.Council__c
con.Date_for_1st_Public_Exhibition__c = opp.Date_for_1st_Public_Exhibition__c
con.Date_for_2nd_Public_Exhibition__c = opp.Date_for_2nd_Public_Exhibition__c
con.Date_to_Call__c = opp.Date_to_Call__c
con.Date_for_Submission__c = opp.Date_for_Submission__c
con.Details_of_Lead__c = opp.Details_of_Lead__c
con.First_Meeting_Report__c = opp.First_Meeting_Report__c
con.IPA_Pitch_Member_1__c = opp.IPA_Pitch_Member_1__c
con.IPA_Pitch_Member_2__c = opp.IPA_Pitch_Member_2__c
con.IPA_Pitch_Member_3__c = opp.IPA_Pitch_Member_3__c
con.Indigo_Email__c = opp.Indigo_Email__c
con.Planning_Committee_Date_Time__c = opp.Planning_Committee_Date_Time__c
con.Previous_contact__c = opp.Previous_contact__c
con.Referersemail__c = opp.Referersemail__c
con.Region__c = opp.Region__c
con.Relevant_Work__c = opp.Relevant_Work__c
con.Sales_Notes__c = opp.Sales_Notes__c
con.Sector__c = opp.Sector__c
con.Is_there_a_URL_where_you_found_this_lead__c = opp.Is_there_a_URL_where_you_found_this_lead__c
conrtlist .add(con );
if(conrtlist.size() > 0){
insert conrtlist ;





You need to write a test class for this and then you can deplpoy it to prod using a change set.
go to Setup>Appsetup >Deploy >Outbound Change Sets

Dear Rahul,


Would you be able to help me do this?  I'm a complete newbie and have been fighting my way around the instructions as to how to do this without success.


I should be so grateful if you would.  


Best regards,




Hi Alex,


I hate to be the bad guy here, but I really think you should hire a developer that can help you with this project. I'm not saying that it's impossible to get help here, but I don't think you should expect the forum here to guide you through an entire project. Sorry :(

Developer for
Voicent provides CRM, auto dialer, predictive dialer, reminder, and call center solution that is suitable for anyone in any level
Voicent strives to meet customer demands to integrate Voicent software with CRM of their choice.