function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
v varaprasadv varaprasad 

Trigger will work on user mode or system mode

Hi All,

Please help me on below issue.


1. Trigger will work on user mode or system mode
2. In below class account is having one contact but one user able to see contact another user not why another user not able to see contact please help me.

3. As per my knowledge below class will work on system mode.
4. Please help me why another user not ble to see the contact.
 
trigger sampleTrigger on account(after update){
  AccountHelper.Createcontact(Trigger.new);
}

If account type == hot then i need create one conatct for account only one contact.
If contact is existing then no need to crete contact.

public class AccountHelper{

 public static void Createcontact(list<account> accs){
  set<id> acciDs = new set<id>(); 
  for(account acc : accs){
   if(acc.type == 'hot'){    
      acciDs.add(acc.id);   
   } 
 }
 list<account> accslist = [select id,name,(select id from contacts) from acount];
 
 for(account acc : accslist){
     if(acc.contacts.size()== 0){
	 
	    //crating contact here 
	 }
 
 }
}

 
pconpcon
I believe you want to change your class to be without sharing [1].
 
public without sharing class AccountHelper {

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm