• ZoomV
  • NEWBIE
  • 0 Points
  • Member since 2013
  • Salesforce Developer
  • BCD Travel

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies

I've written this super easy trigger which only sets a date. I'm still learning how to write test code, so I was wondering if anybody could show me what it would be like for something this simple :

 

trigger SetContractEndDates on Contract_Terms__c (before insert, before update) {

  for (Contract_Terms__c ct : Trigger.new) {
          if (ct.Auto_Renewal_Contract_End_Date__c== null)
          ct.Overall_End_Date__c= ct.Contract_End_Date__c;
        else
          ct.Overall_End_Date__c = ct.Auto_Renewal_Contract_End_Date__c;  
  }
}

 

Thank you very much.

  • May 13, 2013
  • Like
  • 0


This is a trigger which is meant to create child records based upon a multi-value field in a parent record at the time the parent is saved. It doesn't seem to be creating the records upon being saved :

trigger AutoCreateSubs on Contract_Overview__c (after insert) {
 List<Subs_Serviced_On_Contract__c> subs = new List<Subs_Serviced_On_Contract__c>();

    //For each position processed by the trigger, add a new  

    //Subs_Serviced_On_Contract record for the specified Subsidiaries_On_Contract__c.  

    //Note that Trigger.New is a list of all the new positions  

    //that are being created.  

    for (Contract_Overview__c newContract : Trigger.New) {
        if (newContract.Subsidiaries_On_Contract__c != null) {
            // split out the multi-select picklist using the semicolon - or comma -delimiter
            for(String subsoncontract: newContract.Subsidiaries_On_Contract__c.split(',')){
                subs.add(new Subs_Serviced_On_Contract__c(
                        Name = newContract.Id,
                        Contract_Overview__c = newContract.Id,
                        Subsidiary_Name__c = (Id)subsoncontract,
                        Logo_Usage_Allowed__c = 'Yes'));
            }
        } 
    }
    insert subs;

}

 

The trigger is at 100% code coverage and is Active. There is a value in the Subsidiaries_On_Contract_c field, so that wouldn't be preventing it from firing off.

Does anybody see anything wrong with this code which would prevent it from creating the records ? I'm not sure if it is error-ing out or not even firing off. Can somebody give me some direction on this ?

Thank you very much for your help.

 

 

  • March 21, 2013
  • Like
  • 0

I've put together the following test for a trigger. 

@isTest
public with sharing class AutoCreateSubsTriggerTest {

    static testMethod void testAutoCreateSubs() {
        // First, set up your test User.
        User testUser = generateTestUser();

        // Generate your position but don't perform DML yet
        Contract_Overview__c contover = new Contract(Subsidiaries_On_Contract__c = testUser.Id);

        // Start your test and insert your contract overview
        Test.startTest();
        insert contover;
        Test.stopTest();

        // Get the subs from the DB to ensure they were created
        List<Subs_Serviced_On_Contract__c> subs = [SELECT
                                                 Id
                                             FROM
                                                 Subs_Serviced_On_Contract__c
                                             WHERE
                                                 Contract_Overview__c = :contover.Id
        ];

        // There should be 1 interviewer because only one user ID was provided
        System.assert(1, subs.size(), 'One sub object is expected');
    }

    private User generateTestUser(){
        // We use the System Admin profile because it will always be there
        Profile sysAdmin = [SELECT 
                               Id 
                            FROM 
                               Profile 
                            WHERE 
                               Name = 'System Administrator'
                            LIMIT 1
        ];

        // Generate the user
        User newUser = new User(
            UserName = 'unit.tester@example.com',
            LastName = 'Test',
            FirstName = 'Jane',
            Email = 'unit.tester@example.com',
            phone = '555-555-5555',
            MobilePhone = '555-555-5554',
            Street = '123 Fake Street',
            City = 'Los Angeles',
            State = 'CA',
            PostalCode = '12345',
            CommunityNickName = 'unit.test',
            Alias = 'abcd',
            ProfileId = sysAdmin.Id,
            emailencodingkey = 'UTF-8',
            languagelocalekey = 'en_US',
            localesidkey = 'en_US',
            timezonesidkey = 'America/Los_Angeles'
        );

        // Insert that user
        insert user;

        return user;
    }
}

 I am getting the error "Variable does not exist : user". I don't understand how that's happening. Anybody got an idea ? 

Thank you.

  • March 19, 2013
  • Like
  • 0

I am attempting to send a Change Set from one sandbox to another. One of the objects is not being uploaded properly. It is an object which is already on the receiving object. I just want to update it, but nothing is changing. My other uploads are working properly, although none of them were updates, just objects which were not on the receiving sandbox. 

Is there a setting that could be attributable to this ? The receiving object was marked Deployed. I unmarked that in case it had any effect, but it didn't. There are of course other elements from other objects which are dependant on the receiving object, but does that matter to the Deploy process ? If so, how can I solve that - besides deleting all of the fields, classes, and triggers which are dependant on it ? 

 

Thank you.

  • March 14, 2013
  • Like
  • 0

However, I need two things : 

I need the HTML markup code by the current templates which were created on Salesforce's template building process.I would then like to implement that markup into the VF page I will create. I need that in order to maintain the proper appearance layout of the current templates. 


Thank you.

  • March 05, 2013
  • Like
  • 0

I've written this super easy trigger which only sets a date. I'm still learning how to write test code, so I was wondering if anybody could show me what it would be like for something this simple :

 

trigger SetContractEndDates on Contract_Terms__c (before insert, before update) {

  for (Contract_Terms__c ct : Trigger.new) {
          if (ct.Auto_Renewal_Contract_End_Date__c== null)
          ct.Overall_End_Date__c= ct.Contract_End_Date__c;
        else
          ct.Overall_End_Date__c = ct.Auto_Renewal_Contract_End_Date__c;  
  }
}

 

Thank you very much.

  • May 13, 2013
  • Like
  • 0


This is a trigger which is meant to create child records based upon a multi-value field in a parent record at the time the parent is saved. It doesn't seem to be creating the records upon being saved :

trigger AutoCreateSubs on Contract_Overview__c (after insert) {
 List<Subs_Serviced_On_Contract__c> subs = new List<Subs_Serviced_On_Contract__c>();

    //For each position processed by the trigger, add a new  

    //Subs_Serviced_On_Contract record for the specified Subsidiaries_On_Contract__c.  

    //Note that Trigger.New is a list of all the new positions  

    //that are being created.  

    for (Contract_Overview__c newContract : Trigger.New) {
        if (newContract.Subsidiaries_On_Contract__c != null) {
            // split out the multi-select picklist using the semicolon - or comma -delimiter
            for(String subsoncontract: newContract.Subsidiaries_On_Contract__c.split(',')){
                subs.add(new Subs_Serviced_On_Contract__c(
                        Name = newContract.Id,
                        Contract_Overview__c = newContract.Id,
                        Subsidiary_Name__c = (Id)subsoncontract,
                        Logo_Usage_Allowed__c = 'Yes'));
            }
        } 
    }
    insert subs;

}

 

The trigger is at 100% code coverage and is Active. There is a value in the Subsidiaries_On_Contract_c field, so that wouldn't be preventing it from firing off.

Does anybody see anything wrong with this code which would prevent it from creating the records ? I'm not sure if it is error-ing out or not even firing off. Can somebody give me some direction on this ?

Thank you very much for your help.

 

 

  • March 21, 2013
  • Like
  • 0

I've put together the following test for a trigger. 

@isTest
public with sharing class AutoCreateSubsTriggerTest {

    static testMethod void testAutoCreateSubs() {
        // First, set up your test User.
        User testUser = generateTestUser();

        // Generate your position but don't perform DML yet
        Contract_Overview__c contover = new Contract(Subsidiaries_On_Contract__c = testUser.Id);

        // Start your test and insert your contract overview
        Test.startTest();
        insert contover;
        Test.stopTest();

        // Get the subs from the DB to ensure they were created
        List<Subs_Serviced_On_Contract__c> subs = [SELECT
                                                 Id
                                             FROM
                                                 Subs_Serviced_On_Contract__c
                                             WHERE
                                                 Contract_Overview__c = :contover.Id
        ];

        // There should be 1 interviewer because only one user ID was provided
        System.assert(1, subs.size(), 'One sub object is expected');
    }

    private User generateTestUser(){
        // We use the System Admin profile because it will always be there
        Profile sysAdmin = [SELECT 
                               Id 
                            FROM 
                               Profile 
                            WHERE 
                               Name = 'System Administrator'
                            LIMIT 1
        ];

        // Generate the user
        User newUser = new User(
            UserName = 'unit.tester@example.com',
            LastName = 'Test',
            FirstName = 'Jane',
            Email = 'unit.tester@example.com',
            phone = '555-555-5555',
            MobilePhone = '555-555-5554',
            Street = '123 Fake Street',
            City = 'Los Angeles',
            State = 'CA',
            PostalCode = '12345',
            CommunityNickName = 'unit.test',
            Alias = 'abcd',
            ProfileId = sysAdmin.Id,
            emailencodingkey = 'UTF-8',
            languagelocalekey = 'en_US',
            localesidkey = 'en_US',
            timezonesidkey = 'America/Los_Angeles'
        );

        // Insert that user
        insert user;

        return user;
    }
}

 I am getting the error "Variable does not exist : user". I don't understand how that's happening. Anybody got an idea ? 

Thank you.

  • March 19, 2013
  • Like
  • 0