• Sarah Pinns
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hello,  could someone help get my code to have at least 75% code coverage.  I have a catch at the end but when I try to deploy, it says my code coverage is at 0%.  Thank you!
 
trigger createPEActivity on Task (after insert) {
    
    List <SBI_Activity__c> vehToInsert = new List <SBI_Activity__c> ();
    // or whatever your custom object name put instead of RGS_Activity__c
    
    for (Task t : Trigger.new) {
        
        
        // here is where you check if emailmessage that is being inserted
        //meets the criteria
        if (t.OwnerId == '0050f000009ykPo') {
        
        SBI_Activity__c v = new SBI_Activity__c (); //instantiate the object to put values for future record
        
        // now map emailmessage fields to new rgsactivity object that is being created with this emailmessage
        
        v.recordtypeid = '0126f000000Wkk8';
        v.Notes__c = t.Description;
        v.Contact__c = t.WhoId;
        V.Primary_RGM_Phase__c = 'PENDING';
        v.Activity__c = 'PENDING';
        v.Channel__c = 'Human engagement';
        v.Activity_Date__c = t.ActivityDate; // and so on so forth untill you map all the fields. 
        
        //once done, you need to add this new object to the list that would be later inserted. 
        //don't worry about the details for now
        
        vehToInsert.add(v);
        
        
        }//end if
        
    }//end for t
    
    //once loop is done, you need to insert new records in SF
    // dml operations might cause an error, so you need to catch it with try/catch block.
    try{insert vehToInsert;}catch (System.QueryException qe){} 
}



 
Hi! I am looking to trigger a record creation when a task is created.  I would like it to work for if I task is manually created or if it is created through using 'Email to Salesforce'  My code is below but nothing happens when I create task with a status of completed.  Is there something I'm missing?  Appreciate the guidance!
 
trigger createGAActivityonTask on Task (after insert) {
    
    List <RGS_Activity__c> vehToInsert = new List <RGS_Activity__c> ();
    
    
    for (Task o : Trigger.new) {
        
        
        
        if (o.Status == 'Completed') {
        
        RGS_Activity__c v = new RGS_Activity__c (); 
        
        v.Account__c = '001G000001zaW9M';
        v.Contact__c = '00379000004n82q';
        v.Activity__c = 'Email - 1:1'; 
        
        vehToInsert.add(v);
        
        
        }
        
    }
    try {
        insert vehToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

 
Hello,  could someone help get my code to have at least 75% code coverage.  I have a catch at the end but when I try to deploy, it says my code coverage is at 0%.  Thank you!
 
trigger createPEActivity on Task (after insert) {
    
    List <SBI_Activity__c> vehToInsert = new List <SBI_Activity__c> ();
    // or whatever your custom object name put instead of RGS_Activity__c
    
    for (Task t : Trigger.new) {
        
        
        // here is where you check if emailmessage that is being inserted
        //meets the criteria
        if (t.OwnerId == '0050f000009ykPo') {
        
        SBI_Activity__c v = new SBI_Activity__c (); //instantiate the object to put values for future record
        
        // now map emailmessage fields to new rgsactivity object that is being created with this emailmessage
        
        v.recordtypeid = '0126f000000Wkk8';
        v.Notes__c = t.Description;
        v.Contact__c = t.WhoId;
        V.Primary_RGM_Phase__c = 'PENDING';
        v.Activity__c = 'PENDING';
        v.Channel__c = 'Human engagement';
        v.Activity_Date__c = t.ActivityDate; // and so on so forth untill you map all the fields. 
        
        //once done, you need to add this new object to the list that would be later inserted. 
        //don't worry about the details for now
        
        vehToInsert.add(v);
        
        
        }//end if
        
    }//end for t
    
    //once loop is done, you need to insert new records in SF
    // dml operations might cause an error, so you need to catch it with try/catch block.
    try{insert vehToInsert;}catch (System.QueryException qe){} 
}



 

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.