Skip to content

Commit

Permalink
Fixed account / opportunity linking
Browse files Browse the repository at this point in the history
  • Loading branch information
jawills committed Jul 14, 2024
1 parent b74f3ea commit 4a25e4d
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .sfdx/indexes/lwc/custom-components.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"_allAttributes":null,"_properties":null,"_methods":null,"file":"/home/jawills/Documents/1sync/apps/jira-sf-integration/force-app/main/default/lwc/jiraProjectWizard/jiraProjectWizard.js","metadata":{"decorators":[{"type":"api","targets":[{"name":"recordId","type":"property","value":{"type":"unresolved"}},{"name":"objectApiName","type":"property","value":{"type":"unresolved"}}]},{"type":"wire","targets":[{"type":"method","name":"wiredAccount","static":{"fields":{"type":"array","value":[null,null,null]}},"params":{"recordId":"recordId"},"adapter":{"name":"getRecord","reference":"lightning/uiRecordApi"}}]},{"type":"track","targets":[{"name":"account","type":"property"}]}],"classMembers":[{"name":"filter","type":"property","value":{"type":"object","value":{}},"loc":{"start":{"line":12,"column":2},"end":{"line":20,"column":4}}},{"name":"recordId","type":"property","value":{"type":"unresolved"},"decorator":"api","loc":{"start":{"line":22,"column":2},"end":{"line":22,"column":16}}},{"name":"objectApiName","type":"property","value":{"type":"unresolved"},"decorator":"api","loc":{"start":{"line":23,"column":2},"end":{"line":23,"column":21}}},{"name":"account","type":"property","decorator":"track","loc":{"start":{"line":24,"column":2},"end":{"line":24,"column":17}}},{"name":"available","type":"property","loc":{"start":{"line":25,"column":2},"end":{"line":25,"column":12}}},{"name":"notCheckedKey","type":"property","value":{"type":"boolean","value":true},"loc":{"start":{"line":26,"column":2},"end":{"line":26,"column":23}}},{"name":"projectCreationDisable","type":"property","value":{"type":"boolean","value":true},"loc":{"start":{"line":27,"column":2},"end":{"line":27,"column":32}}},{"name":"projectName","type":"property","loc":{"start":{"line":28,"column":2},"end":{"line":28,"column":14}}},{"name":"projectLead","type":"property","loc":{"start":{"line":29,"column":2},"end":{"line":29,"column":14}}},{"name":"key","type":"property","loc":{"start":{"line":30,"column":2},"end":{"line":30,"column":6}}},{"name":"error","type":"property","loc":{"start":{"line":31,"column":2},"end":{"line":31,"column":8}}},{"name":"wiredAccount","type":"method","decorator":"wire","loc":{"start":{"line":32,"column":2},"end":{"line":52,"column":3}}},{"name":"handleKeyChange","type":"method","loc":{"start":{"line":53,"column":2},"end":{"line":55,"column":3}}},{"name":"handleNameChange","type":"method","loc":{"start":{"line":56,"column":2},"end":{"line":59,"column":3}}},{"name":"handleLeadChange","type":"method","loc":{"start":{"line":60,"column":2},"end":{"line":63,"column":3}}},{"name":"checkProjectCreation","type":"method","loc":{"start":{"line":65,"column":2},"end":{"line":69,"column":3}}},{"name":"handleKeyCheck","type":"method","loc":{"start":{"line":71,"column":2},"end":{"line":79,"column":3}}},{"name":"handleProjectCreate","type":"method","loc":{"start":{"line":81,"column":2},"end":{"line":106,"column":3}}}],"declarationLoc":{"start":{"line":11,"column":0},"end":{"line":107,"column":1}},"doc":"","exports":[{"type":"ExportDefaultDeclaration"}]},"updatedAt":"2024-07-13T14:20:04.305Z"},{"_allAttributes":null,"_properties":null,"_methods":null,"file":"/home/jawills/Documents/1sync/apps/jira-sf-integration/force-app/main/default/lwc/jiraVersionWizard/jiraVersionWizard.js","metadata":{"decorators":[{"type":"api","targets":[{"name":"recordId","type":"property","value":{"type":"unresolved"}},{"name":"objectApiName","type":"property","value":{"type":"unresolved"}}]}],"classMembers":[{"name":"nameField","type":"property","value":{"type":"unresolved"},"loc":{"start":{"line":9,"column":2},"end":{"line":9,"column":27}}},{"name":"recordId","type":"property","value":{"type":"unresolved"},"decorator":"api","loc":{"start":{"line":12,"column":2},"end":{"line":12,"column":16}}},{"name":"objectApiName","type":"property","value":{"type":"unresolved"},"decorator":"api","loc":{"start":{"line":13,"column":2},"end":{"line":13,"column":21}}},{"name":"handleVersionCreate","type":"method","loc":{"start":{"line":15,"column":2},"end":{"line":36,"column":3}}}],"declarationLoc":{"start":{"line":7,"column":0},"end":{"line":37,"column":1}},"doc":"","exports":[{"type":"ExportDefaultDeclaration"}]},"updatedAt":"2024-07-13T14:20:04.309Z"}]
[]
Binary file modified .sfdx/tools/250/apex.db
Binary file not shown.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,32 @@
You can install with the SF CLI:

```bash
sf package install --package 04tQl0000008hpNIAQ --target-org your-org
sf package install --package 04tQl0000008iGnIAI --target-org your-org
```

Or use the install links:

- [Production](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tQl0000008hpNIAQ)
- [Sandbox](https://test.salesforce.com/packaging/installPackage.apexp?p0=04tQl0000008hpNIAQ)
- [Production](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tQl0000008iGnIAI)
- [Sandbox](https://test.salesforce.com/packaging/installPackage.apexp?p0=04tQl0000008iGnIAI)

## Setup

### Jira Authentication

The integration uses Basic Authentication in Jira to create the authentication. We can get the Jira credentials by:
The integration uses Basic Authentication in Jira to create the authentication. We also need to store this information in a named credential.

We can get the Salesforce Named Credential by installing the following package:

```bash
sf package install --package 04tQl0000008iIPIAY --target-org your-org
```

- [Production](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tQl0000008iIPIAY)
- [Sandbox](https://test.salesforce.com/packaging/installPackage.apexp?p0=04tQl0000008iIPIAY)

**WARNING** - Installing this package will override any existing Jira Named Credentials in your org.

We can get the Jira credentials by:

1. Get the [API Token](https://id.atlassian.com/manage/api-tokens)
2. Inside Salesforce, go to Setup -> Named Credential. Update the `your-domain` inside the Jira Named Credential, update the URL to your JIRA Domain
Expand Down
2 changes: 1 addition & 1 deletion jira-integration/core/classes/issue/JIRAIssueMapping.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public without sharing class JIRAIssueMapping {
c.Subject = issue.fields.summary;
// c.Description = issue.fields.description; //@TODO description is an object and needs to be parsed
c.JIRA_Project_Id__c = issue.fields.project.id;
projectIds.add(issue.fields.project.id);
projectIds.add(c.JIRA_Project_Id__c);
c.JIRA_Key__c = issue.key;
c.Status = issue.fields.status.name;
c.Time_Spent__c = issue.fields.aggregatetimespent;
Expand Down
36 changes: 36 additions & 0 deletions jira-integration/core/classes/issue/JIRAIssueTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ public class JIRAIssueTest {
static void makeData(){
Account a = new Account();
a.Name = 'Test Account';
a.JIRA_Project_Id__c = '1234';
insert a;

Opportunity opp = new Opportunity();
opp.Name = 'Test opp';
opp.CloseDate = Date.today();
opp.StageName = 'Closed Won';
opp.JIRA_Version_Id__c = '5678';
opp.AccountId = a.Id;
insert opp;
}

@isTest(seeAllData=false)
Expand Down Expand Up @@ -53,4 +62,31 @@ public class JIRAIssueTest {

System.assert(caseList.size() > 0, 'No cases were created.');
}

@isTest(seeAllData=false)
static void testController() {
Test.setMock(HttpCalloutMock.class, new Mock());
Case c = new Case();
c.JIRA_Issue_Id__c = '11755';
insert c;
ApexPages.StandardController stdController = new ApexPages.StandardController(
c
);
JiraIssueController controller = new JiraIssueController(
stdController
);
Test.startTest();
controller.sync();
Test.stopTest();

Case afterUpdate = [SELECT Id, JIRA_Key__c, Opportunity__c, JIRA_Version_Id__c, JIRA_Project_Id__c, AccountId FROM Case WHERE Id =: c.Id];
Opportunity opp = [SELECT Id FROM Opportunity WHERE JIRA_Version_Id__c = '5678'];
System.assert(String.isNotBlank(afterUpdate.JIRA_Key__c), 'Key was never set');
System.assertEquals('1234', afterUpdate.JIRA_Project_Id__c, 'Project Id Incorrect');
System.assert(String.isNotBlank(afterUpdate.AccountId), 'Account was never set');
System.assertEquals('5678', afterUpdate.JIRA_Version_Id__c, 'Version Id incorrect');
System.assertEquals(opp.Id, afterUpdate.Opportunity__c, 'Opportunity not linked');


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class JIRAIssueQueryJSON_Test {
' \"customfield_10030\": null,'+
' \"project\": {'+
' \"self\": \"https://1sync.atlassian.net/rest/api/3/project/10024\",'+
' \"id\": \"10024\",'+
' \"id\": \"1234\",'+
' \"key\": \"ZED\",'+
' \"name\": \"ZED Project\",'+
' \"projectTypeKey\": \"software\",'+
Expand All @@ -48,7 +48,7 @@ public class JIRAIssueQueryJSON_Test {
' \"fixVersions\": ['+
' {'+
' \"self\": \"https://1sync.atlassian.net/rest/api/3/version/10022\",'+
' \"id\": \"10022\",'+
' \"id\": \"5678\",'+
' \"description\": \"TEST Opp\",'+
' \"name\": \"hello\",'+
' \"archived\": false,'+
Expand Down
3 changes: 2 additions & 1 deletion jira-integration/core/lwc/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"include": [
"**/*",
"../../../../.sfdx/typings/lwc/**/*.d.ts"
"../../../../.sfdx/typings/lwc/**/*.d.ts",
"../../../.sfdx/typings/lwc/**/*.d.ts"
],
"paths": {
"c/*": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<QuickAction xmlns="http://soap.sforce.com/2006/04/metadata">
<height>250</height>
<label>Pull From JIRA</label>
<optionsCreateFeedItem>false</optionsCreateFeedItem>
<page>JIRACaseVF</page>
<type>VisualforcePage</type>
<width>-100</width>
</QuickAction>
15 changes: 10 additions & 5 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"path": "jira-integration/core",
"default": true,
"package": "Jira Integration - Core",
"versionName": "Case Controller",
"versionNumber": "0.4.0.NEXT",
"versionName": "ver 0.1",
"versionNumber": "0.1.0.NEXT",
"releaseNotesUrl": "https://github.com/jawills/jira-sf-integration/releases",
"versionDescription": "Added individual record sync for issues on the case. And fixed a bug where opportunities and accounts weren't linking to the case."
"versionDescription": ""
},
{
"path": "jira-integration/auth",
"package": "Jira Integration - Auth",
"versionName": "ver 0.1",
"versionNumber": "0.1.0.NEXT",
"releaseNotesUrl": "https://github.com/jawills/jira-sf-integration/releases",
"default": false,
"versionDescription": ""
}
Expand All @@ -31,6 +32,10 @@
"Jira [email protected]": "04tQl0000008hm9IAA",
"Jira [email protected]": "04tQl0000008hnlIAA",
"Jira [email protected]": "04tQl0000008hpNIAQ",
"Jira Integration - Auth": "0HoQl00000000XtKAI"
"Jira Integration - Auth": "0HoQl00000000XtKAI",
"Jira Integration - Core": "0HoQl00000000ZVKAY",
"Jira Integration - [email protected]": "04tQl0000008hsbIAA",
"Jira Integration - [email protected]": "04tQl0000008iGnIAI",
"Jira Integration - [email protected]": "04tQl0000008iIPIAY"
}
}
}

0 comments on commit 4a25e4d

Please sign in to comment.