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
Mr WodaMr Woda 

Create a trigger for Account object, so when created new Account should be created and linked to "Custom User"

AnkaiahAnkaiah (Salesforce Developers) 
Hi Woda,

Account is lookup to user object?

Thanks!!
Mr WodaMr Woda
yes
AnkaiahAnkaiah (Salesforce Developers) 
Hi Woda,

which user you need to link to the account when created.?

Thanks!!
Mr WodaMr Woda
Hi Ankaiah , "Custom User"
AnkaiahAnkaiah (Salesforce Developers) 
Hi Woda,

Do you have existing user with the name of "Custom User" ?

if yes, try with below code.
 
trigger Userinsert on Account (before insert) {
    
    List<user> users = [select id from user where Name='Custom User' limit 1];
    
    for(account acc:trigger.new ){
        
        if(acc.user__c == Null){
            acc.user__c = users[0].id;
        }
    }

}

If this helps, Please mark it as best answer.

Thanks!!