+ Start a Discussion

Trying to run test for simple trigger

I'm new to Apex and am trying to get this test script to work so that I can deploy the trigger over to production.  The trigger works in our Sandbox, but my test script keeps returning null.  I'm not sure what is going on.  On our account record we have a lookup field to the user table.  This is the id i'm trying to pull.  The account record is the master and we have a custom object that stems from account called program.  We then have another custom object that stems from program, RS.  The trigger is to take place on the RS record on the before update event.  This field is what will determine who gets an automated approval submission.  It's a funky setup, but due to other objects/setups, we had to go this route.  When I run my test, the system debug is always showing null after the update statement.  I'm not sure what to do next.  Please help!


Tigger Code:

trigger RMuserIDupdate on Revenue_Share__c (before update) {
    for(revenue_share__c rs: trigger.new){
        ID pID = [select RM_Detail_Link__c from revenue_share__c where id = :rs.id].rm_detail_link__C;
        ID aID = [select client__c from program__c where id = :pid].client__c;
        id rmID = [select relationship_manager__c from account where id = :aid].relationship_manager__C;
        rs.rm_user_id__c = rmID;


Test Script:

public class Check_RMUserUpdate{
    static testMethod void testCheck_RMUserUpdate() {
    ID testRMID;
    ID actRMID;

    Account A1 = new Account();
    A1.name = 'Test1';
    A1.RecordTypeId = '01240000000DRwY';
    A1.billingcity = 'Kansas City';
    A1.billingstate = 'MO';
    A1.billingpostalcode = '64105';
    A1.site = 'Kansas City MO';
    A1.relationship_manager__C = '005400000012HxuAAE';
    insert a1;
    testrmid = a1.relationship_manager__c;
    Program__c P1 = new Program__c();
    P1.client__c = A1.id;
    insert p1;
    system.debug('********************Program****** ' + p1.id);
    Revenue_Share__C RS1 = new Revenue_Share__c();
    RS1.rm_detail_link__c = p1.id;
    //RS1.rm_user_id__c = '00540000000xC6yAAE';
    insert RS1;
    system.debug('********************rm detail****** ' + rs1.rm_detail_link__c);

    rs1.tier__c = 'B1';
    update rs1;
    actrmid = rs1.rm_user_id__c;
    system.debug('********************TEST****** ' + testrmid + ' ' + actrmid);

Is this id present in Production?


A1.relationship_manager__C = '005400000012HxuAAE'


Yes, the ID is present in production.  Does that matter since the testing is being done in the Sandbox?  The only difference between the two user accounts is the profile, but that shouldn't matter since all I'm wanting to update is the field with the ID.


Looks like I got it to work.  At least the system.debug statement shows both IDs equaling. 


I had to add

    Revenue_Share__c rs2= [SELECT rm_user_id__c FROM Revenue_Share__c WHERE Id = :rs1.Id];

after my update statement. 


Will try to deploy now. 


Usually, id's should be avoided when we migrate any code in production as there is an chance of deactivating the user.


Since there is a change in profile, can you please check if the profile in Production has access to all the fields you are using in the trigger?