With sharing doesn't work with triggers

Sample Code:

Trigger:

trigger sample on Account (after insert, after update) {
    Sample1.test(trigger.new);
}


Controller:

public with sharing class Sample1{
    public static void test(List<Account> acctList){
        List<Employee__c> empList = new List<Employee__c>();
        for(Account a : acctList){
            Employee__c e = new Employee__c(Name = 'Testing');
            empList.add(e);        
        }      
        insert empList; 
    }
}


If an user with no access to Employee object creates an account or updates an account, Employee record with the name, "Testing" will be created with created by name as him/her.

With Sharing doesn't work with triggers.

Cheers!!!


No comments:

Post a Comment