# S-Docs Jobs Testing

This article will cover common and unique use cases that can be tested with SDJobs and through the Developer Console.

## Basis Use Case: 1 Record, 1 template

```apex
Opportunity opp = [SELECT Id FROM Opportunity WHERE Name Like '%Halli Airport%' LIMIT 1];
SDOC__SDTemplate__c template = [SELECT Id FROM SDOC__SDTemplate__c WHERE Name = 'Opportunity Template'];

SDOC__SDJob__c sdjob = new SDOC__SDJob__c(
    SDOC__ObjAPIName__c='Opportunity', // Object API Name
    SDOC__OID__c=opp.id, // Object ID
    SDOC__Doclist__c=template.id, // Template ID
    SDOC__Start__c=true, // Generate document upon insertion of S-Docs Job
    SDOC__SendEmail__c='0' // Send the email Automatically. Change to 1 
    
);
insert sdjob;
```

## Dynamic List of Templates and Files Included In Email Sent:

```apex
Opportunity opp = [SELECT Id FROM Opportunity WHERE Name Like '%Halli Airport%' LIMIT 1];

List<ContentDocumentlink> documents = [SELECT ContentDocument.latestpublishedversionid from ContentDocumentlink where LinkedEntityID=:opp.id];
List<id> documentList = new List<id>();
for (ContentDocumentlink document : documents) {
    documentList.add(document.Id);
}

List<SDOC__SDTemplate__c> templates = [SELECT Id FROM SDOC__SDTemplate__c WHERE Name in ('Opportunity Template','Opportunity Email Template')];
List<id> templateList = new List<id>();
for (SDOC__SDTemplate__c template : templates) {
    templateList.add(template.Id);
}

SDOC__SDJob__c sdjob = new SDOC__SDJob__c(
    SDOC__ObjAPIName__c='Opportunity', // Object API Name
    SDOC__OID__c=opp.id, // Object ID
    SDOC__Doclist__c=String.join(templateList, ','), // Template ID
    SDOC__Start__c=true, // Generate document upon insertion of S-Docs Job
    SDOC__SendEmail__c='1', // Send the email Automatically. Change to 1
    SDOC__Include_All_Related_Files__c=true, 
    SDOC__Fid__c=String.join(documentList, ',')
    
);
insert sdjob;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/maintenance-and-troubleshooting/legacy-workflows/s-doc-jobs-legacy/s-docs-jobs-testing-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
