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
AlexRitsonDevAlexRitsonDev 

Installing my first piece of Apex code

I am now, finally, in a position to deploy the code which a kind developer on this board wrote for me a couple of weeks ago.  The hold-up was in getting our organisation upgraded to Enterprise edition, which has now been done.

 

I have downloaded and installed the force.com IDE, but I am a complete newbie and am now absolutely terrified.  What do I need to do to get this code actually installed on our company's Salesforce system?

 

 

I notice thae Salesforce.com have a requirement that 75%, and preferably 100% of the code be covered by automated tests.  I assume I need to find out how to do this?

 

Someone, please help!

 

Best regards,

 

Alex.

simple-forcesimple-force
Hey Alex,

you have to add a test class like here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm

Your triggers need a minimum of 1 % and all classes and triggers must be covered in average by 75%

Christian
AlexRitsonDevAlexRitsonDev

Sorry, I'm really new to this and am out of my depth.  Can you walk me through this please?

AlexRitsonDevAlexRitsonDev
Also, if I've read this correctly, testing it in the developer console doesn't lead me any closer to actually deploying my code in my Enterprise installation - hence why I am trying to work out how to use Force.com IDE?
simple-forcesimple-force

The force.com IDE is an editor for apex and visulforce code (and other metadata). You should create for every class and trigger a test class that looks like this. Using the IDE you can create a new class like one of these:

 

Here is a sample class for you

 

public class helloWorld

{

public String sayHelloTo(String name)

{

return 'Hello! '+name;

}

}

 

 

//Test Class

@isTest

public Test_helloWorld

{

static testMethod void myUnitTest() {
     helloWorld computer = new helloWorld();

     System.assertEquals('Hello Peter', computer.sayHelloTo('Peter'));
}

}

AlexRitsonDevAlexRitsonDev

Sorry, just to be clear - I need help putting the code into place.

 

The code is this. 

 

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 = 6;
conrtlist .add(con );
}
}
if(conrtlist.size() > 0){
insert conrtlist ;
}
}

 


Please could someone help me use the force.com IDE (or whatever is most appropriate) to deploy this in my company's Salesforce org?

AlexRitsonDevAlexRitsonDev

Actually, an updated version of that code is this:

 

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'){
System.Debug('Testing');
Contract con = new Contract();
if(opp.AccountId != NULL){
con .AccountId = opp.AccountId;
System.Debug('Test');
}

con .Status = 'Draft';
system.debug('Testing1');
con .StartDate = System.Today();
system.debug('Testing2');
con .ContractTerm = 6;
system.debug('Testing3');
con.X1_RESEARCH_People__c = opp.X1_RESEARCH_People__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 ;
system.debug('Testing4');
}
}

 

 

Anyone who can help me get this installed on my org ASAP, I shall be very grateful indeed.

 

 

AlexRitsonDevAlexRitsonDev

Or even, with better formatting:

 

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 = 6;
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 ;
}
}