# About ClientFactory

cldfs.ClientFactory returns a runtime or test instance of Client, so managed-package callouts can be mocked.

> Kind: Guide · Updated: 2026-07-05

As the name suggests, cldfs.ClientFactory is a class built on the Factory pattern which returns a runtime instance or a test instance depending on the context.

Since you would've already written code using cldfs.Client static methods, the first step would be to modify this code to use cldfs.ClientFactory's instance methods instead. Don't worry, this would be simple enough since signatures for each method in both of these classes remain the same.

Here's an example of how to change such a piece of code, we'll take for example the Create Attachments method -

```apex
//Using cldfs.Client static methods

List<cldfs.Types.CreateAttachmentInput> inputs = new List<cldfs.Types.CreateAttachmentInput>{
    new cldfs.Types.CreateAttachmentInput(<folder id>, 'folder', <salesforce record id>, 'b!ZfA15HRS1Uy9pH3Vw5tFjAHfP1lRYlZAvDwLnHYYq8sa-L6ejXB-TJbMYUxi1QfL')
};
List<cldfs.Attachment> attachments = cldfs.Client.createAttachments(
   inputs,
  'sharepoint',
  'integrationUser'
);


//Converted code to use cldfs.ClientFactory instance methods

List<cldfs.Types.CreateAttachmentInput> inputs = new List<cldfs.Types.CreateAttachmentInput>{
    new cldfs.Types.CreateAttachmentInput(<folder id>, 'folder', <salesforce record id>, 'b!ZfA15HRS1Uy9pH3Vw5tFjAHfP1lRYlZAvDwLnHYYq8sa-L6ejXB-TJbMYUxi1QfL')
};

cldfs.ClientFactory client = cldfs.ClientFactory.getInstance();

List<cldfs.Attachment> attachments = client.createAttachments(
   inputs,
  'sharepoint',
  'integrationUser'
);
```
