0

I am a Salesforce Adminstrator with no coding skills and am kindly asking you to help me out with my project.

I have created two custom objects.

  1. Employee (holds records of all employees regardless if they are Salesforce users or not; each employee has its own record)
  2. Knowledge Base (an object holding records with release articles, update articles etc.)

For each Knowledge Base record created I would like to select employees it is concerning from the multiselect picklist. Then I would like a trigger populating 2 fileds in each employee record (depending on which ones I selected in multi select picklist) to be populated.

The field names in the employees records are: Knowledge_Base__c (Lookup(Knowledge Base)) [to be populate with value of Name standard field in Knowledge Base) Knowledge_Base_Link__c (URL(255)) [to be populated with the URL of the Knowledge Base record]

I am happy for the fields on the Employee record to be overriden whenever a knew Knowledge Base record is submitted and same employees are selected.

I would really appreciate if someone could help me with this.

Regards,

Matt

3
  • I like to suggest you. Pls proceed with your trigger development. If you face any issue while development. ASk here in community. There are so many people they are always ready to help you Thanks.
    – Ratan Paul
    Nov 27, 2015 at 18:06
  • What is the name of the multi-select pick list field that has the employee name?
    – Eric
    Nov 27, 2015 at 18:06
  • The name is Select_Employees__c Nov 30, 2015 at 9:20

1 Answer 1

0

Here is a stab at it (Feeling festive).

Notes:

  1. Not sure what you mean by "URL of the Knowledge Base Record" if by that you mean the Salesforce Knowledge_Base__c record url, you do not need this because the lookup will already be linked to it. If it is a field on the Knowledge base then you will have to modify the code appropriately.

  2. This basically assumes that the last record inserted will be what is used to populate the employees. You said you did not care so I did not add any logic into it.

    trigger updateEmployee on Knowledge_Base__c(After Insert){
    
    
    Map<String,Employee__c> NameToEmployee = New Map<String,Employee__c>();
    
    for(Knowledge_Base__c kb : trigger.new){
        if(!string.isBlank(kb.Employee__c){
            for(String nm : kb.Employee__c.split(';')){
                NameToEmployee.put(nm, null);
    
            } 
        }
    }
    
    for(Employee__c emp : [Select ID, Name From Employee__c Where Name In :NameToEmployee.keySet()]){
        NameToEmployee.put(emp.Name,emp);
    }
    
    for(Knowledge_Base__c kb : trigger.new){
        //See if the map has the employee name in it Assumes the Employee__c is a Text Field
        if(!string.isBlank(kb.Employee__c){
            for(String nm : kb.Employee__c.split(';')){
                if(NameToEmployee.containsKey(nm) && NameToEmployee.get(nm) != null){
    
                    NameToEmployee.get(nm).Knowledge_Base__c = kb.id;
                    NameToEmployee.get(nm).Knowledge_Base_Link__c = kb.Knowledge_Base_Link__c; //Not sure what the field name is for your URL. If it is just to the record then you do not need this field at all as the lookup field will suffice
                }
            }
        }
    }
    
    update NameToEmployee.values();
    
    }
    

Disclaimer: May not compile and may require basic debugging

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .