Salesforce-B2C-Commerce-Cloud-Developer Practice Test

Salesforce Spring 25 Release
202 Questions

A developer is asked to create a new service instance that will call a remote web service.
Which method should the developer use to create the service instance?

A. Option A

B. Option B

C. Option C

A.   Option A

Explanation:

In Salesforce B2C Commerce, when a developer needs to call a remote web service, they define and manage the service using the Service Framework. The recommended and standard method to create or register a service instance is:

dw.svc.LocalServiceRegistry.createService(serviceID, definitionObject)

This method registers a new service dynamically in code by associating a service ID (defined in Business Manager) with a JavaScript implementation object that provides:
createRequest
parseResponse
mockCall (for testing)
getRequestLogMessage
getResponseLogMessage

🔧 Example:
var LocalServiceRegistry = require('dw/svc/LocalServiceRegistry');
var myService = LocalServiceRegistry.createService('my.http.service', {
createRequest: function(svc, params) {
svc.setRequestMethod('GET');
return null;
},
parseResponse: function(svc, response) {
return response.text;
}
});

Then call it like:
var result = myService.call();

Why Other Options Are Incorrect:

B. dw.svc.LocalServiceInstance.createService()
❌ Invalid class — there is no LocalServiceInstance in the SFCC Service Framework

C. dw.svc.LocalServiceRegistry.getDefaultService()
❌ This is for retrieving a default, already-registered service — not for creating one

📘 Reference:
Salesforce B2C Commerce Service Framework Docs

Salesforce-B2C-Commerce-Cloud-Developer Practice-Test - Home Previous
Page 15 out of 202 Pages