• hickmand1
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

I',m newbie to apex.  I've written a basic Apex trigger that creates a new custom record when a Lead is created.  I now need to write a test in order to deploy it..... I have no clue where to start.  Please help!

 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Trigger createAMSLead_c on Lead (after insert) {
    
    List <AMS_Leads__c> AMSLeadsInsert = new List <AMS_Leads__c> ();
        for (Lead o : Trigger.new) {
        if (o.LeadSource == 'Lead from Med4All website') {
        AMS_Leads__c v = new AMS_Leads__c (); 
        v.Campaign_Lead_Info__c = o.Id; 
        v.Email_Address__c = o.Email;
        v.Notes__c = o.Description;
        v.Home_Work__c = o.Phone;
        v.Cell_Phone__c = o.MobilePhone;
        v.Date_Time_of_Response__c = system.NOW();
        v.Follow_Up_Method__c = 'Telephonic - Outsource'; 
        
              
        AMSLeadsInsert.add(v);
        
        
       } 
       
    }
        try {
        insert AMSLeadsInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
        }
        }

OK so I've been an admin for about 3 years and (for better or worse) know more about SF than anyone in my company.  i have some experience with apex and Visualforce, but little with triggers.

 

what i need is to write a trigger in production that does this:  the trigger should create a new record in a custom object called "Vehicles" when an Opportunity record is created with a specific value in one of its custom fields (the field is called "Type").  So, when an opp is created and saved with Type = "x", then the trigger should fire, and a new vehicle object record should be created that is populated with a few fields from that opportunity record.

 

can anyone send me some code to show me what this trigger should be or look like?  I've been researching this but have no clue, and I'm afraid of writing bad code that will cause problems.

 

also, the custom object is not in a parent-child relationship with the opporuntiy object, and i don't want it to be unless it has to be.

 

i know the developers in here are ridiculously smart and talented, and i'm just hoping one of you feels sorry enough for an amateur like me to help me out.  thanks a lot.