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
AlexRitsonAlexRitson 

My code is missing a method - help please!

I'm a newbie and have, with the help of some very kind people on these boards, assembled some code that should enable us to convert Opportunities to Contracts.  Once this is working, I shall be happy to share this with everyone, as I know that I am not the first person to have needed this functionality.

 

Frustratingly, there is, according to Salesforce, still a missing couple of lines of code somewhere around line 2 - the method.

 

Would very much appreciate help from anyone who can make this work for me.

 

Best regards,

 

Alex.

public with sharing class CreatecontractonOppstageclosewon {
{
Set<Id> accId = new Set<Id>();
List<Opportunity> opplist = new List<Opportunity>();
List<contract> conrtlist = new List<contract>();
for(Opportunity opp : Trigger.new){
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 = opp.Length_of_project_months__c;
con.X2_RESEARCH_LPA__c = opp.X2_RESEARCH_LPA__c
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 ;
}
}
}

 

AmulAmul

Do you really want to convert your opportunity through trigger or on Button action click. If you are choosing trigger then your logic should be like trigger OnOpprtunityUpdate on Opportunity(before update){ Set accId = new Set(); List opplist = new List(); List conrtlist = new List(); for(Opportunity opp : Trigger.new){ 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 = opp.Length_of_project_months__c; con.X2_RESEARCH_LPA__c = opp.X2_RESEARCH_LPA__c 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 ; } }

AlexRitsonAlexRitson

Thank you very much for this.

 

I just tried this, adding the line you suggested in (see full code below), using Force.com IDE

 

Frustratingly, I am getting a failure - here is the error log.

 

Your advice most welcome.

 

*** Deployment Log ***

Result: FAILED

Date: September 11, 2013 1:01:28 PM BST

 

# Deployed From:

   Project name: Contracts

   Username: alex.ritson@indigopa.com

   Endpoint: www.salesforce.com

 

# Deployed To:

   Username: alex.ritson@indigopa.com

   Endpoint: www.salesforce.com

 

# Deploy Results:

   File Name:    package.xml

   Full Name:  package.xml

   Action:  NO ACTION

   Result:  FAILED

   Problem: Cannot deploy InstalledPackage in Package Manifest with any other types!

 

# Test Results:

   n/a

 

 

public with sharing class CreatecontractonOppstageclosewon {
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 : Trigger.new){
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 = opp.Length_of_project_months__c;
con.X2_RESEARCH_LPA__c = opp.X2_RESEARCH_LPA__c
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 ;
}
}
}

 

AmulAmul
There are two things One is development and another one is deployment part. So Once your development is finished salesforce require TEST Class for each component.

So if you have defined some trigger then you need to write Test Class for it.