• Michael Ludwig
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hi,

I came across a strange behavior when writing a trigger, not sure if I am missing the obvious somewhere.
Here is the situation:
We have a custom object called Interest_Tag__c. Among other information, the record has a checkbox which by default is set to false.
The process is the following:
As soon as a record of record type 'Raw data' is created, some of the information from that record is used to create a new Interest_Tag__c record, but with a different record type. Both records exist in the system later, however, the 'Raw data' record type should have the checkbox set to 'true', while the second Interest_tag__c record should have the checkbox set to 'false'.
Below is the basic structure for the trigger I am testing at the moment, you see the portion for 'Before Insert'.
it.Completely_Converted__c = true should update the record with the 'Raw data' record type, I also explicitely set NewActTag.Completely_Converted__c= false and the debug statement for TagsToCreate shows completely_converted = false for the second record.
When trying to insert a new record of type 'Raw Data', two records are created with different record types (works as planned), but both of them have the checkbox set to true.
When commenting out it.Completely_Converted__c = true, both records have the checkbox unchecked.

Any hint would be appreciated, maybe I don't seethe wood for the trees :-)
IF(Trigger.isBefore && Trigger.isInsert){
        
        Set<String> ActivityParts = new Set<String>();
        Set<ID> ActivityGPLID = new Set<ID>();
        Map<String, RecordType> rtMap = new Map<String, RecordType>();
        String rt;
        Map<String, Contact> Contacts = new Map<String, Contact>();
        Set<String> TagEmails = new Set<String>();
        Interest_Tag__c NewActTag = new Interest_Tag__c();
        List<Product_Hierarchy__c> ProductHierarchyList= new List<Product_Hierarchy__c>();
        Map<String, Part__c> TagParts = new Map<String, Part__c>();
        List<Interest_Tag__c> TagsToCreate = new List<Interest_Tag__c>();
        
        FOR(RecordType rt1 : [SELECT Name FROM RecordType WHERE SobjectType ='Interest_Tag__c']){
            rtMap.put(rt1.Name, rt1);
        }
        
        FOR(Interest_Tag__c it : Trigger.New){
            IF(it.Record_Type_Name__c == 'Raw Data' && it.Completely_Converted__c == false){
                ActivityParts.add(it.Part_Number_Text__c);
                TagEmails.add(it.Email_from_Activity_or_Contact_Role__c);    
            }
            FOR(Part__c p1 :[SELECT Product_Hierarchy__c, Name FROM Part__c WHERE Part__c.Name in :ActivityParts] ){
                ActivityGPLID.add(p1.Product_Hierarchy__c); 
                Tagparts.put(p1.Name, p1);
            }
            FOR(Product_Hierarchy__c ph1 :[SELECT ID, Name FROM Product_Hierarchy__c WHERE ID in :ActivityGPLID] ){
                ProductHierarchyList.add(ph1); 
            }
            FOR(Contact con1 :[SELECT email FROM Contact WHERE Email in :TagEmails]){
                Contacts.put(con1.Email, con1);
            }
            
            IF(it.Activity_Rating_Desc__c=='3D PDF'){
                rt = rtMap.get('Interest Tag Final 3D PDF').id;
            }ELSE
                IF(it.Activity_Rating_Desc__c=='Sample request'){
                    rt = rtMap.get('Interest Tag Final Sample Request').id;    
                }ELSE
                    IF(it.Activity_Rating_Desc__c=='CAD Model'){
                        rt = rtMap.get('Interest Tag Final CAD').id;   
                    }
            For (Product_Hierarchy__c ph2 :ProductHierarchyList){
                NewActTag.RecordTypeId= rt;
                
                NewActTag.Area_of_Interest__c = ph2.Name;
                NewActTag.Contact__c = Contacts.get(it.Email_from_Activity_or_Contact_Role__c).id;
                NewActTag.Part__c = Tagparts.get(it.Part_Number_Text__c).id;
                NewActTag.GPL__c = ph2.Id;
                NewActTag.Completely_Converted__c= false;
                TagsToCreate.add(NewActTag);
            }
            
            it.Completely_Converted__c = true;
        }
        Insert TagsToCreate;
        System.debug(TagsToCreate);
    }

 
Hi,

I am running into some issues when running a test class in which I do a system.assert for a trigger on accounts I have written.
The trigger is relatively simple, it checks two fields on the account record and if changed or if a new account is created, it populates two other fields with corresponding values that I retrieve from a custom setting.

The trigger works fine when I test it in the UI, here is the code:
 
trigger BU_Update on Account (before insert, before update) {
    
    
    Map<String, String> DD1Values = new Map<String, String>(); //map to hold values from DD1 Custom Setting
    For(DD1_Definition__c dd1 : [SELECT DD1_Code__c, DD1_Business_Unit__c FROM DD1_Definition__c]){
        DD1Values.put(dd1.DD1_Code__c, dd1.DD1_Business_Unit__c);
    }
    Map<String, String> DD2Values = new Map<String, String>(); // map to hold values from DD2 Custom Setting
    For(DD2_Definition__c dd2 : [SELECT DD2_Code__c, DD2_Business_Unit__c FROM DD2_Definition__c]){
        DD2Values.put(dd2.DD2_Code__c, dd2.DD2_Business_Unit__c);
    }
    
    //Compare old and new values for DD1 and DD2 codes, retrieve new value if changed
    For (Account a : Trigger.New){
        
        IF(Trigger.isInsert && Trigger.isBefore && a.RecordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account').getRecordTypeId()){
            
            a.Industry_Code_Description__c = DD1Values.get(a.DD1_Industry_Business_Code__c);
            a.Business_Unit_Level_2__c  = DD2Values.get(a.DD2_Industry_Business_Code__c);
            
        }   
        
        IF(Trigger.isUpdate && Trigger.isBefore && a.RecordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account').getRecordTypeId()){
            
            IF (a.DD1_Industry_Business_Code__c != Trigger.OldMap.get(a.Id).DD1_Industry_Business_Code__c){
                a.Industry_Code_Description__c = DD1Values.get(a.DD1_Industry_Business_Code__c);
            }
            IF (a.DD2_Industry_Business_Code__c != Trigger.OldMap.get(a.Id).DD2_Industry_Business_Code__c){
                a.Business_Unit_Level_2__c  = DD2Values.get(a.DD2_Industry_Business_Code__c);
            }
            
        }
    }
    
}
Here is my test class:
 
@isTest
public class Account_BU_Update_Test {
    
    
    
    static testmethod void testall(){
        ClsTestCustomSettingHelper.getAllSettings();
        ClsTestCustomSettingHelper.getPMV_Sales_Stage_Setting();
        ChannelinsightData_test.ChannelinsightData_test();
        ClsTestCustomSettingHelper.getTrigger_Configuration();
        
        RecordType rt = ClsTestHelp.createTestRecordType8();
        Account acc2 = ClsTestHelp.createTestAccounts();
        acc2.RecordTypeId =rt.Id;
        acc2.Account_Manager__c = UserInfo.getUserId();
        acc2.DD1_Industry_Business_Code__c = '001';
        acc2.DD2_Industry_Business_Code__c = '105';
        acc2.Name = 'Test account Michael';
        insert acc2;
        
        
        Test.startTest();
        
        acc2=[Select id, Industry_Code_Description__c, Business_Unit_Level_2__c FROM Account WHERE ID =:acc2.Id];
        System.assertEquals('Automotive', acc2.Industry_Code_Description__c);
        
        Test.stopTest();
        
    }
    
    
}
I need to include a few helper classes at the beginning and I am also creating a new account record with a helper class.
If I don't do a system assert, code coverage is fine, but I don't get why the system.assert would return:

System.AssertException: Assertion Failed: Expected: Automotive, Actual: null

I create a test record, insert it, query it again, including the field Industry_Code_Description__c, but the value for it continues to be null.
I verified that the account has the correct record type for the trigger and if I do the same test in the UI it works without any problems.
For the test data above I set the DD1_Industry_Business_code to '001' and in my custom setting the corresponing value would be 'Automotive'.

Any ideas where I might miss something ?

Thanks.
 
Hi,

I have inherited a VF page that uses the slds framework and I am trying to get my head around it.
I am fairly new to visual force, but I understand the logic in the site and the controller.
I did ask the developer the following question:

When using this component for example:

<div class="slds-page-header" role="banner">

Where do I find a reference about all the attributes that can be used in the page header class and what values are allowed ?
In other words, how do I know what values are allowed for the 'role'attribute above and are there any other attributes available for 'role' ?
The slds homepage doesn't seem to provide that information, at least I have not found it.

Many thanks

Michael
Hi,

another newbie, on my track from Admin to Dev.
I am just going through the Trailhead module for Visualforce. All ok so far, I am managing ok, I guess.

I have one question regarding standard list controller. In one module it says:

When the page loads, the <apex:selectList> builds a menu of available filters, by getting the list from the {! listViewOptions } expression. listViewOptions is a property provided by the standard list controller.

While I understand what is happening I would like to know where can I find all the properties that the standard list controller provides ?
Where is the reference in the VF developer guide ?

Thanks.

Michael
Hi, did anybody participate in the recent webinar Building Beautiful Apps Part I: The Idea on 5th November ? Is there a recording available at all ? Thanks
Hi,

I came across a strange behavior when writing a trigger, not sure if I am missing the obvious somewhere.
Here is the situation:
We have a custom object called Interest_Tag__c. Among other information, the record has a checkbox which by default is set to false.
The process is the following:
As soon as a record of record type 'Raw data' is created, some of the information from that record is used to create a new Interest_Tag__c record, but with a different record type. Both records exist in the system later, however, the 'Raw data' record type should have the checkbox set to 'true', while the second Interest_tag__c record should have the checkbox set to 'false'.
Below is the basic structure for the trigger I am testing at the moment, you see the portion for 'Before Insert'.
it.Completely_Converted__c = true should update the record with the 'Raw data' record type, I also explicitely set NewActTag.Completely_Converted__c= false and the debug statement for TagsToCreate shows completely_converted = false for the second record.
When trying to insert a new record of type 'Raw Data', two records are created with different record types (works as planned), but both of them have the checkbox set to true.
When commenting out it.Completely_Converted__c = true, both records have the checkbox unchecked.

Any hint would be appreciated, maybe I don't seethe wood for the trees :-)
IF(Trigger.isBefore && Trigger.isInsert){
        
        Set<String> ActivityParts = new Set<String>();
        Set<ID> ActivityGPLID = new Set<ID>();
        Map<String, RecordType> rtMap = new Map<String, RecordType>();
        String rt;
        Map<String, Contact> Contacts = new Map<String, Contact>();
        Set<String> TagEmails = new Set<String>();
        Interest_Tag__c NewActTag = new Interest_Tag__c();
        List<Product_Hierarchy__c> ProductHierarchyList= new List<Product_Hierarchy__c>();
        Map<String, Part__c> TagParts = new Map<String, Part__c>();
        List<Interest_Tag__c> TagsToCreate = new List<Interest_Tag__c>();
        
        FOR(RecordType rt1 : [SELECT Name FROM RecordType WHERE SobjectType ='Interest_Tag__c']){
            rtMap.put(rt1.Name, rt1);
        }
        
        FOR(Interest_Tag__c it : Trigger.New){
            IF(it.Record_Type_Name__c == 'Raw Data' && it.Completely_Converted__c == false){
                ActivityParts.add(it.Part_Number_Text__c);
                TagEmails.add(it.Email_from_Activity_or_Contact_Role__c);    
            }
            FOR(Part__c p1 :[SELECT Product_Hierarchy__c, Name FROM Part__c WHERE Part__c.Name in :ActivityParts] ){
                ActivityGPLID.add(p1.Product_Hierarchy__c); 
                Tagparts.put(p1.Name, p1);
            }
            FOR(Product_Hierarchy__c ph1 :[SELECT ID, Name FROM Product_Hierarchy__c WHERE ID in :ActivityGPLID] ){
                ProductHierarchyList.add(ph1); 
            }
            FOR(Contact con1 :[SELECT email FROM Contact WHERE Email in :TagEmails]){
                Contacts.put(con1.Email, con1);
            }
            
            IF(it.Activity_Rating_Desc__c=='3D PDF'){
                rt = rtMap.get('Interest Tag Final 3D PDF').id;
            }ELSE
                IF(it.Activity_Rating_Desc__c=='Sample request'){
                    rt = rtMap.get('Interest Tag Final Sample Request').id;    
                }ELSE
                    IF(it.Activity_Rating_Desc__c=='CAD Model'){
                        rt = rtMap.get('Interest Tag Final CAD').id;   
                    }
            For (Product_Hierarchy__c ph2 :ProductHierarchyList){
                NewActTag.RecordTypeId= rt;
                
                NewActTag.Area_of_Interest__c = ph2.Name;
                NewActTag.Contact__c = Contacts.get(it.Email_from_Activity_or_Contact_Role__c).id;
                NewActTag.Part__c = Tagparts.get(it.Part_Number_Text__c).id;
                NewActTag.GPL__c = ph2.Id;
                NewActTag.Completely_Converted__c= false;
                TagsToCreate.add(NewActTag);
            }
            
            it.Completely_Converted__c = true;
        }
        Insert TagsToCreate;
        System.debug(TagsToCreate);
    }

 
Hi,

I am running into some issues when running a test class in which I do a system.assert for a trigger on accounts I have written.
The trigger is relatively simple, it checks two fields on the account record and if changed or if a new account is created, it populates two other fields with corresponding values that I retrieve from a custom setting.

The trigger works fine when I test it in the UI, here is the code:
 
trigger BU_Update on Account (before insert, before update) {
    
    
    Map<String, String> DD1Values = new Map<String, String>(); //map to hold values from DD1 Custom Setting
    For(DD1_Definition__c dd1 : [SELECT DD1_Code__c, DD1_Business_Unit__c FROM DD1_Definition__c]){
        DD1Values.put(dd1.DD1_Code__c, dd1.DD1_Business_Unit__c);
    }
    Map<String, String> DD2Values = new Map<String, String>(); // map to hold values from DD2 Custom Setting
    For(DD2_Definition__c dd2 : [SELECT DD2_Code__c, DD2_Business_Unit__c FROM DD2_Definition__c]){
        DD2Values.put(dd2.DD2_Code__c, dd2.DD2_Business_Unit__c);
    }
    
    //Compare old and new values for DD1 and DD2 codes, retrieve new value if changed
    For (Account a : Trigger.New){
        
        IF(Trigger.isInsert && Trigger.isBefore && a.RecordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account').getRecordTypeId()){
            
            a.Industry_Code_Description__c = DD1Values.get(a.DD1_Industry_Business_Code__c);
            a.Business_Unit_Level_2__c  = DD2Values.get(a.DD2_Industry_Business_Code__c);
            
        }   
        
        IF(Trigger.isUpdate && Trigger.isBefore && a.RecordTypeId == Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account').getRecordTypeId()){
            
            IF (a.DD1_Industry_Business_Code__c != Trigger.OldMap.get(a.Id).DD1_Industry_Business_Code__c){
                a.Industry_Code_Description__c = DD1Values.get(a.DD1_Industry_Business_Code__c);
            }
            IF (a.DD2_Industry_Business_Code__c != Trigger.OldMap.get(a.Id).DD2_Industry_Business_Code__c){
                a.Business_Unit_Level_2__c  = DD2Values.get(a.DD2_Industry_Business_Code__c);
            }
            
        }
    }
    
}
Here is my test class:
 
@isTest
public class Account_BU_Update_Test {
    
    
    
    static testmethod void testall(){
        ClsTestCustomSettingHelper.getAllSettings();
        ClsTestCustomSettingHelper.getPMV_Sales_Stage_Setting();
        ChannelinsightData_test.ChannelinsightData_test();
        ClsTestCustomSettingHelper.getTrigger_Configuration();
        
        RecordType rt = ClsTestHelp.createTestRecordType8();
        Account acc2 = ClsTestHelp.createTestAccounts();
        acc2.RecordTypeId =rt.Id;
        acc2.Account_Manager__c = UserInfo.getUserId();
        acc2.DD1_Industry_Business_Code__c = '001';
        acc2.DD2_Industry_Business_Code__c = '105';
        acc2.Name = 'Test account Michael';
        insert acc2;
        
        
        Test.startTest();
        
        acc2=[Select id, Industry_Code_Description__c, Business_Unit_Level_2__c FROM Account WHERE ID =:acc2.Id];
        System.assertEquals('Automotive', acc2.Industry_Code_Description__c);
        
        Test.stopTest();
        
    }
    
    
}
I need to include a few helper classes at the beginning and I am also creating a new account record with a helper class.
If I don't do a system assert, code coverage is fine, but I don't get why the system.assert would return:

System.AssertException: Assertion Failed: Expected: Automotive, Actual: null

I create a test record, insert it, query it again, including the field Industry_Code_Description__c, but the value for it continues to be null.
I verified that the account has the correct record type for the trigger and if I do the same test in the UI it works without any problems.
For the test data above I set the DD1_Industry_Business_code to '001' and in my custom setting the corresponing value would be 'Automotive'.

Any ideas where I might miss something ?

Thanks.
 
Hi,

I have inherited a VF page that uses the slds framework and I am trying to get my head around it.
I am fairly new to visual force, but I understand the logic in the site and the controller.
I did ask the developer the following question:

When using this component for example:

<div class="slds-page-header" role="banner">

Where do I find a reference about all the attributes that can be used in the page header class and what values are allowed ?
In other words, how do I know what values are allowed for the 'role'attribute above and are there any other attributes available for 'role' ?
The slds homepage doesn't seem to provide that information, at least I have not found it.

Many thanks

Michael
Hi,

another newbie, on my track from Admin to Dev.
I am just going through the Trailhead module for Visualforce. All ok so far, I am managing ok, I guess.

I have one question regarding standard list controller. In one module it says:

When the page loads, the <apex:selectList> builds a menu of available filters, by getting the list from the {! listViewOptions } expression. listViewOptions is a property provided by the standard list controller.

While I understand what is happening I would like to know where can I find all the properties that the standard list controller provides ?
Where is the reference in the VF developer guide ?

Thanks.

Michael