How to create External Object record synchronously using Apex?

How to create External Object record synchronously using Apex?

Database.insertImmediate() method can be used to create External Object record synchronously using Apex.

Sample Code:

Test__x objTest = new Test__x();
objTest.PK__c = '3';
objTest.SK__c = 'Test3';
objTest.Name__c = 'Test3';
Database.SaveResult objSR = Database.insertImmediate( 
    objTest 
);
System.debug( 'Created successfully? ' + objSR.isSuccess() );

Output:

Leave a Reply