+ Start a Discussion
Matt Blatnik 8Matt Blatnik 8 

Relating multiple records and assigning tasks


I have two custom objects: Library and employees. Each employee record represents information about a user in the company. One of the fields is department.

In library i publish useful articles. 

How can I make salesforce search and assign tasks to employees to read a publisehd article when i select department "marketing" in the library object. Same field and value exists in employee object.

to sum up - when I publish an article for marketing I want each employee in markteing to get a task to read the article.
Hi Matt ,

You have to write an apex trigger on library object like 

trigger test on library__c (before insert) {
        if(trigger.new.get(0).department__c !=null)
            list<employ__c> listOfEmploy=[Select ID from employ__c where Department__c= :trigger.new.get(0).department__c ];
        List<Task>  taskToInsert = new List<Task>();
        for(employ__c aa : listOfEmploy)    
            if(aa.department__c !=trigger.oldMap().get(aa.ID) )
                 Task T = new Task();
                T.Type = 'Email';
                T.Description = ''; //string
                T.OwnerId = aa.ID; //user id
                T.WhatId = ''; //record id
insert taskToInsert;

There may be some syntax errors . But it will definately  solve your problem.
Feel free to ask any query

Suman Kumari 76Suman Kumari 76
Hi I need help