0

I Have used Enforce Security With the stripInaccessible Method to Create Record in Account Object

List<Account> newAccounts = new List<Account>();
Account a = new Account(Name='Acme Corporation');
Account b = new Account(Name='Blaze Comics');
newAccounts.add(a);
newAccounts.add(b);
 
SObjectAccessDecision securityDecision = Security.stripInaccessible(
                                         AccessType.CREATABLE, newAccounts);
insert securityDecision.getRecords();

Now I want to get the Record Id of each record inserted in Account Object. Can you help me on this.

1

The Security.stripInaccessible method returns the list of SObject. Once you insert this list, it should have the IDs as well.

List<Account> newAccounts = new List<Account>();
Account a = new Account(Name='Acme Corporation 1');
Account b = new Account(Name='Blaze Comics 1');
newAccounts.add(a);
newAccounts.add(b);

SObjectAccessDecision securityDecision = Security.stripInaccessible(
        AccessType.CREATABLE, newAccounts);
List<Account> accounts =  securityDecision.getRecords();

insert accounts;
System.debug(accounts); // Will have the IDs
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.