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
AnshiiAnshii 

Insert an account record to user

Hi everyone,
my scenario is to insert an account  record  to the particular user which  i have created in my org .and that account has only read access.how to insert an account record to particular user using apex can some one help.
when i login as that user i need to see  the record which i have inserted.

Thanks in Advance.
Best Answer chosen by Anshii
Suraj Tripathi 47Suraj Tripathi 47

Hi  Arroju Anusha,

Query particular user assign the account to them

User u=[Select id,Name from User where Name='abc'];

Account ac=new Account();
ac.Name='Test';
ac.OwnerId=u.id;

insert ac;

Please follow the below link :https://developer.salesforce.com/forums/?id=906F00000008ypLIAQ

Thank You

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi  Arroju Anusha,

Query particular user assign the account to them

User u=[Select id,Name from User where Name='abc'];

Account ac=new Account();
ac.Name='Test';
ac.OwnerId=u.id;

insert ac;

Please follow the below link :https://developer.salesforce.com/forums/?id=906F00000008ypLIAQ

Thank You

This was selected as the best answer
AnshiiAnshii
Thanks a lot
AnshiiAnshii
Hi ,
How can i Throw error message if that user does not have permission on particular object  to the above scenario.