• Craig Grove
  • NEWBIE
  • 40 Points
  • Member since 2014
  • SFDC Admin
  • MEDNAX National Group


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 14
    Replies
Hello,

     I've created the below trigger so that our Telemarketing (Inside Sales) initiatives will open an Opportunity if the Inside Sales record's outcome__c field = "Meeting Scheduled". I have a lookup field for each object linking them. I have code to pass the originating record's id to the lookup field of the created record, but I need to get the new record's id sent back to the lookup field on the originating record. The lookup field on the originating record is Opportunity__c. Any assistance is appreciated.

trigger OpportunityCreate on Inside_Sales__c (after Update) {

//The purpose of this trigger is to automatically create an open opportunity when a telemarketer
//has successfully scheduled a meeting or presentation in reference to an inside sales initiative
//This trigger kicks off when an inside sales initiative has an outcome of meeting scheduled or present. scheduled

    //Here we are creating a list of Opportunity records
    //We create a lists or batches so that we can avoid exceeding governor limits
    List<Opportunity> Opps = new List<Opportunity>();
   
    //Here we are specifying to run the trigger only if the if statemenet is met
    //We have multiple if statements
    for (Inside_Sales__c updatedInsideSales : Trigger.New){ 
    
         //Here we are stating to run the trigger if outcome equals meeting scheduled
        if(updatedInsideSales.CreateOpp__c == True){
        
            //If the above if statement was met the below parameters will be passed
            Opps.add(new Opportunity(
                AccountId = updatedInsideSales.Account_Name__c,
                OwnerID = updatedInsideSales.Sales_Manager__c,
                InsideSales__c = updatedInsideSales.Id,
                Telemarketing__c = 'Yes',
                Name = updatedInsideSales.Account_Name_Text__c,
                Owner_s_Region__c = updatedInsideSales.PDX_Region__c,
                StageName = 'Presentation',       
                CloseDate = date.today()+60));
            }
        }

    //Here we are inserting the opportunity records
    insert Opps;
   
}
Hi all, I'm having a code coverage issue that I'm hoping you can assist with. I have issues in the same place in a few similarly formulated triggers. Please see the below, error points are bolded:


trigger InsideSalesRollover on Inside_Sales__c (after Update) {
    List<Inside_Sales__c> rollover = new List<Inside_Sales__c>();
    
    for(Inside_Sales__c updatedsales : Trigger.New){
        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q1'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q2',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c));           
        } 

        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q2'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q3',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c)); 
        }   
        
        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q3'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q4',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c));
        }
        
        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q4'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q1',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c));
        }       
    }
    insert rollover;   
}

Here is the test class:

@IsTest
private class InsideSalesRollover {

    static testmethod void InsideSalesRollover() {
        
         Region__c reg = new Region__c(
            name = 'Test Region');
        insert reg;
            
        Account acc = new Account(
            name = 'Test Account',
            Practice_Location_Street__c = '123 My Way',
            Practice_Location_City__c = 'Farmville',
            Practice_Location_Zip_Code__c = '12345',
            Practice_Location_State__c = 'Florida',
            PDX_Region__c = reg.id);
        insert acc;  
        
        RecordType rtype = [Select name From RecordType where sObjectType='Inside_Sales__c' and isActive=true and name='Business Expansion'];
        
        Inside_Sales__c sales = new Inside_Sales__c();
            sales.RecordType = rtype;
            sales.Purpose__c = 'Schedule Meeting';
            sales.Account_Name__c = acc.id;
            sales.Status__c = 'Pending Approval';
        insert sales;
        
            sales.status__c = 'Rejected';
        update sales;
    }
}
 
In line 28 below, Sales_Manager__c = '00570000001AJxn', Sales Manager__c is a user field. If I use a hard coded id, this test class works, however, my goal is to not use hard coded ids. I attempted to pull a list of users limited to 1 user, row 20, to call single user into the Sales_Manager__c field. The apex looked as such, Sales_Manager__c = usr. Any advise on how to get this to work is greatly appreciated. Thanks in advance.

@isTest

public class OpportunityCreateTest {
     
    static testmethod void addInsideSales(){
                       
        Region__c reg = new Region__c(
            name = 'Test Region');
        insert reg;
            
        Account acc = new Account(
            name = 'Test Account',
            Practice_Location_Street__c = '123 My Way',
            Practice_Location_City__c = 'Farmville',
            Practice_Location_Zip_Code__c = '12345',
            Practice_Location_State__c = 'Florida',
            PDX_Region__c = reg.id);
        insert acc;
        
        List<User> usr = [Select id From User where Department='Business Expansion' and isActive=True Limit 1];
        List<RecordType> rtype = [Select name From RecordType where sObjectType='Account' and isActive=true and name='Current HS Program'];
        
        Inside_Sales__c salesa = new Inside_Sales__c(
            RecordType = rtype,
            Account_Name__c = acc.id,
            Purpose__c = 'Schedule Meeting', 
            Status__c = 'Not Started',
            Sales_Manager__c = '00570000001AJxn');
        insert salesa;    
    
        Inside_Sales__c salesu = salesa;
            salesu.Status__c = 'Completed';
            salesu.Outcome__c = 'Meeting Scheduled';
        update salesu;
    }
}
I've created a trigger to create child objects when a lookup field is changed on the parent object.  Instance: Parent Object =Laptop__c; Child object=Laptop_Update__c; Field=Location__c(Account). I was able to create and deploy successfully a trigger and class based upon creating a new Laptop and triggering the creatiion of the laptop updates, but when attempting to create a similar trigger and class based on information update on Laptop__c I ran into issues. Any assistance is appreciated.

Trigger:

trigger CreateIHSLaptopUpdate2 on Laptop__c (after Update) {
    List<IHS_Laptop_Updates__c> Updates = new List<IHS_Laptop_Updates__c>();
  
    //For each Laptop processed by the trigger, add a new
    //Update record for the specified user.
    //Note that Trigger.New is a list of all new Laptops
    //That are being created.
  
    for (Laptop__c updatedLaptop: Trigger.New) {
        if(updatedLaptop.Location__c !='0017000000bSTpd')
        if(updatedLaptop.Location__c !='0017000000YRiPy'){
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'AEP Software',
                Version__c = '2.36B ALI',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'IHS Auto Software Update',
                Version__c = '1.55',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Central Internet Site',
                Version__c = 'N/A',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Manual',
                Version__c = '2.32',
                IHS_Laptop__c = updatedLaptop.Id));
        }
    }

    insert Updates;
}

Test Class:

@IsTest
private class TestTrigger3 {

    static testmethod void testtrigger() {
   
        //Add Account
        Account A = new Account();
            A.Name = 'Test';
           
        insert A;
   
        //Add Laptop
        Laptop__c L = new Laptop__c();
            L.Name = 'Test';
       
        insert L;
       
        //Update Laptop
            L.Location__c = a.id;
        update L;
    }
}
I'm new to triggers and apex, but was attempting a simple trigger to create a child object on Contact object. Goal is to establish a contact to account relationship when creating a contact using the contacts Name and Account to populate the relationship object. Here is the trigger I wrote, which worked in Sandbox.

trigger CreateContactAccountAssociation on Contact (after insert)
{    List<Contact_Account_Association__c> Associations = new List<Contact_Account_Association__c>();
 
    //For each Contact processed by the trigger, add a new
    //Association record for the specified user.
    //Note that Trigger.New is a list of all new Contacts
    //That are being created.
 
    for (Contact newContact: Trigger.New) {
        if (newContact.RecordTypeId !='012700000009iHg' ) {
            Associations.add(new Contact_Account_Association__c(
                Account__c = newContact.AccountId,
                Contact__c = newContact.Id));
        }
    }

    insert Associations;
}

Trigger worked in Sandbox......Created below apex class  which passed in Sandbox

@IsTest(SeeAllData=True)
public class TestTrigger {

    static testmethod void insertContact() {
  
        Contact u = new Contact();
      
            u.Salutation = 'Mr.';
            u.FirstName = 'Test';
            u.LastName = 'Trigger';
            u.AccountId = '00170000011BckQ';
      
        insert u;
    }
}

Received below errors when deploying to production

Deployment Validation Errors

Any assistance is appreciated!!
Hello,

     I've created the below trigger so that our Telemarketing (Inside Sales) initiatives will open an Opportunity if the Inside Sales record's outcome__c field = "Meeting Scheduled". I have a lookup field for each object linking them. I have code to pass the originating record's id to the lookup field of the created record, but I need to get the new record's id sent back to the lookup field on the originating record. The lookup field on the originating record is Opportunity__c. Any assistance is appreciated.

trigger OpportunityCreate on Inside_Sales__c (after Update) {

//The purpose of this trigger is to automatically create an open opportunity when a telemarketer
//has successfully scheduled a meeting or presentation in reference to an inside sales initiative
//This trigger kicks off when an inside sales initiative has an outcome of meeting scheduled or present. scheduled

    //Here we are creating a list of Opportunity records
    //We create a lists or batches so that we can avoid exceeding governor limits
    List<Opportunity> Opps = new List<Opportunity>();
   
    //Here we are specifying to run the trigger only if the if statemenet is met
    //We have multiple if statements
    for (Inside_Sales__c updatedInsideSales : Trigger.New){ 
    
         //Here we are stating to run the trigger if outcome equals meeting scheduled
        if(updatedInsideSales.CreateOpp__c == True){
        
            //If the above if statement was met the below parameters will be passed
            Opps.add(new Opportunity(
                AccountId = updatedInsideSales.Account_Name__c,
                OwnerID = updatedInsideSales.Sales_Manager__c,
                InsideSales__c = updatedInsideSales.Id,
                Telemarketing__c = 'Yes',
                Name = updatedInsideSales.Account_Name_Text__c,
                Owner_s_Region__c = updatedInsideSales.PDX_Region__c,
                StageName = 'Presentation',       
                CloseDate = date.today()+60));
            }
        }

    //Here we are inserting the opportunity records
    insert Opps;
   
}
Hi all, I'm having a code coverage issue that I'm hoping you can assist with. I have issues in the same place in a few similarly formulated triggers. Please see the below, error points are bolded:


trigger InsideSalesRollover on Inside_Sales__c (after Update) {
    List<Inside_Sales__c> rollover = new List<Inside_Sales__c>();
    
    for(Inside_Sales__c updatedsales : Trigger.New){
        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q1'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q2',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c));           
        } 

        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q2'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q3',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c)); 
        }   
        
        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q3'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q4',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c));
        }
        
        if(updatedsales.Roll_Over__c == True)
        if(updatedsales.Rotation_Period__c == 'Q4'){
            rollover.add(new Inside_Sales__c(
                Rolled_Over__c = True,
                Sales_Manager__c = updatedsales.Sales_Manager__c,
                Telemarketer__c = updatedsales.Telemarketer__c,
                RecordTypeid = updatedsales.RecordTypeid,
                Account_Name__c = updatedsales.Account_Name__c,
                Status__c = 'Pending Approval',
                Rotation_Period__c = 'Q1',
                RG_Approver__c = updatedsales.RG_Approver__c,
                BD_Approver__c = updatedsales.BD_Approver__c,
                AA_Approver__c = updatedsales.AA_Approver__c));
        }       
    }
    insert rollover;   
}

Here is the test class:

@IsTest
private class InsideSalesRollover {

    static testmethod void InsideSalesRollover() {
        
         Region__c reg = new Region__c(
            name = 'Test Region');
        insert reg;
            
        Account acc = new Account(
            name = 'Test Account',
            Practice_Location_Street__c = '123 My Way',
            Practice_Location_City__c = 'Farmville',
            Practice_Location_Zip_Code__c = '12345',
            Practice_Location_State__c = 'Florida',
            PDX_Region__c = reg.id);
        insert acc;  
        
        RecordType rtype = [Select name From RecordType where sObjectType='Inside_Sales__c' and isActive=true and name='Business Expansion'];
        
        Inside_Sales__c sales = new Inside_Sales__c();
            sales.RecordType = rtype;
            sales.Purpose__c = 'Schedule Meeting';
            sales.Account_Name__c = acc.id;
            sales.Status__c = 'Pending Approval';
        insert sales;
        
            sales.status__c = 'Rejected';
        update sales;
    }
}
 
In line 28 below, Sales_Manager__c = '00570000001AJxn', Sales Manager__c is a user field. If I use a hard coded id, this test class works, however, my goal is to not use hard coded ids. I attempted to pull a list of users limited to 1 user, row 20, to call single user into the Sales_Manager__c field. The apex looked as such, Sales_Manager__c = usr. Any advise on how to get this to work is greatly appreciated. Thanks in advance.

@isTest

public class OpportunityCreateTest {
     
    static testmethod void addInsideSales(){
                       
        Region__c reg = new Region__c(
            name = 'Test Region');
        insert reg;
            
        Account acc = new Account(
            name = 'Test Account',
            Practice_Location_Street__c = '123 My Way',
            Practice_Location_City__c = 'Farmville',
            Practice_Location_Zip_Code__c = '12345',
            Practice_Location_State__c = 'Florida',
            PDX_Region__c = reg.id);
        insert acc;
        
        List<User> usr = [Select id From User where Department='Business Expansion' and isActive=True Limit 1];
        List<RecordType> rtype = [Select name From RecordType where sObjectType='Account' and isActive=true and name='Current HS Program'];
        
        Inside_Sales__c salesa = new Inside_Sales__c(
            RecordType = rtype,
            Account_Name__c = acc.id,
            Purpose__c = 'Schedule Meeting', 
            Status__c = 'Not Started',
            Sales_Manager__c = '00570000001AJxn');
        insert salesa;    
    
        Inside_Sales__c salesu = salesa;
            salesu.Status__c = 'Completed';
            salesu.Outcome__c = 'Meeting Scheduled';
        update salesu;
    }
}
I've created a trigger to create child objects when a lookup field is changed on the parent object.  Instance: Parent Object =Laptop__c; Child object=Laptop_Update__c; Field=Location__c(Account). I was able to create and deploy successfully a trigger and class based upon creating a new Laptop and triggering the creatiion of the laptop updates, but when attempting to create a similar trigger and class based on information update on Laptop__c I ran into issues. Any assistance is appreciated.

Trigger:

trigger CreateIHSLaptopUpdate2 on Laptop__c (after Update) {
    List<IHS_Laptop_Updates__c> Updates = new List<IHS_Laptop_Updates__c>();
  
    //For each Laptop processed by the trigger, add a new
    //Update record for the specified user.
    //Note that Trigger.New is a list of all new Laptops
    //That are being created.
  
    for (Laptop__c updatedLaptop: Trigger.New) {
        if(updatedLaptop.Location__c !='0017000000bSTpd')
        if(updatedLaptop.Location__c !='0017000000YRiPy'){
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'AEP Software',
                Version__c = '2.36B ALI',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'IHS Auto Software Update',
                Version__c = '1.55',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Central Internet Site',
                Version__c = 'N/A',
                IHS_Laptop__c = updatedLaptop.Id));
            Updates.add(new IHS_Laptop_Updates__c(
                Type__c = 'Manual',
                Version__c = '2.32',
                IHS_Laptop__c = updatedLaptop.Id));
        }
    }

    insert Updates;
}

Test Class:

@IsTest
private class TestTrigger3 {

    static testmethod void testtrigger() {
   
        //Add Account
        Account A = new Account();
            A.Name = 'Test';
           
        insert A;
   
        //Add Laptop
        Laptop__c L = new Laptop__c();
            L.Name = 'Test';
       
        insert L;
       
        //Update Laptop
            L.Location__c = a.id;
        update L;
    }
}
I'm new to triggers and apex, but was attempting a simple trigger to create a child object on Contact object. Goal is to establish a contact to account relationship when creating a contact using the contacts Name and Account to populate the relationship object. Here is the trigger I wrote, which worked in Sandbox.

trigger CreateContactAccountAssociation on Contact (after insert)
{    List<Contact_Account_Association__c> Associations = new List<Contact_Account_Association__c>();
 
    //For each Contact processed by the trigger, add a new
    //Association record for the specified user.
    //Note that Trigger.New is a list of all new Contacts
    //That are being created.
 
    for (Contact newContact: Trigger.New) {
        if (newContact.RecordTypeId !='012700000009iHg' ) {
            Associations.add(new Contact_Account_Association__c(
                Account__c = newContact.AccountId,
                Contact__c = newContact.Id));
        }
    }

    insert Associations;
}

Trigger worked in Sandbox......Created below apex class  which passed in Sandbox

@IsTest(SeeAllData=True)
public class TestTrigger {

    static testmethod void insertContact() {
  
        Contact u = new Contact();
      
            u.Salutation = 'Mr.';
            u.FirstName = 'Test';
            u.LastName = 'Trigger';
            u.AccountId = '00170000011BckQ';
      
        insert u;
    }
}

Received below errors when deploying to production

Deployment Validation Errors

Any assistance is appreciated!!