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
Jasril Dane CaliwagJasril Dane Caliwag 

hi all, i want to create a code after insert with a condition that if the Owner is equal to "WOWLink Site Guest User" , it will change the owner to "SELECT Id from User WHERE Profile = 'API Only' AND Role != null" someone please help me out

here is the after insert code in my account trigger handler:
 
public override  void afterInsert(){
        String childTransferUser = JSON.serialize(trigger.New);
        if(!Test.isRunningTest()){
            childAccount(childTransferUser);
        }
        createAccShare(Trigger.New);
   
        //Check if owner is WOWLink Site Guest User
        //if yes change the owner to SELECT Id from User WHERE Profile = 'API Only' AND Role != null
    }

please help me out
Raj VakatiRaj Vakati
Sample code is here .. You need to use before insert to assign the owner 
 
public override  void afterInsert(){
        String childTransferUser = JSON.serialize(trigger.New);
        if(!Test.isRunningTest()){
            childAccount(childTransferUser);
        }
        createAccShare(Trigger.New);
   
        //Check if owner is WOWLink Site Guest User
        //if yes change the owner to SELECT Id from User WHERE Profile = 'API Only' AND Role != null
    }
	
	
	public override  void before(){
     User u = [  SELECT Id from User WHERE Profile = 'API Only' AND Role != null Limit 1 ];
   
        //Check if owner is WOWLink Site Guest User
		String pid = [Select Id from profile where name ='WOWLink Site Guest User'].id ; 
		if(UserInfo.getProfieId == pid){
		//set CaseiD 
		c.OwnerId =u.Id ;
		
		}
        //if yes change the owner to 
    }