Salesforce Intergration Alert Echo
Asked by Mike Almon:

I have setup integration between Opsgenie and a Salesforce Developer Environment. I want to retain the ability to open, update, or close an alert/case in 1 environment and it will change the corresponding alert/case in the other. And for the most part that is working.

The 1 problem that I am seeing is when I create ticket in Opsgenie that creates a Salesforce case as expected, but the creation of Salesforce case triggers the creation of a new Opsgenie Alert.

The ideal sate:

New Opsgenie Alert -\> Creates -\> New Salesforce Case

New Salesforce Case -\> Creates -\> New Opsgenie Alert

What I am Seeing:

New Opsgenie Alert -\> Creates -\> New Salesforce Case -\> Creates -\> New Different Opsgenie Alert

New Salesforce Case -\> Creates -\> New Opsgenie Alert

I did try to apply a filter to cont create alerts from Salesforce cases container the word Prometheus as most if not all alerts will be generated from Prometheus but it does not seem to work. That is the only change made from the default configuration.

![Screenshot from 2021-11-19 15-55-07.png](/t5/image/serverpage/image-id/170267i9A0F970510CD2C45/image-size/large?v=v2&px=999 "Screenshot from 2021-11-19 15-55-07.png")![Screenshot from 2021-11-19 15-56-26.png](/t5/image/serverpage/image-id/170268i197312A9C20F7306/image-size/large?v=v2&px=999 "Screenshot from 2021-11-19 15-56-26.png")![Screenshot from 2021-11-19 15-57-59.png](/t5/image/serverpage/image-id/170269i0CA7148916061F34/image-size/large?v=v2&px=999 "Screenshot from 2021-11-19 15-57-59.png")![Screenshot from 2021-11-19 15-58-30.png](/t5/image/serverpage/image-id/170270i9C7248F766F3D7C9/image-size/large?v=v2&px=999 "Screenshot from 2021-11-19 15-58-30.png")


Answers:
author: Connor Eyles
body: Hi [@Mike Almon](/t5/user/viewprofilepage/user-id/4643233)

We have reached out to the development team to gain a better understanding around this loop that seems to be happening, I will reply back once we get an update from the development team!

Thanks,

Connor

comments: author: Connor Eyles
body: Hey [@Mike Almon](/t5/user/viewprofilepage/user-id/4643233)

The following code block contains a minor change that passes the opsgenie-alias back to the Opsgenie. Can you please save the following as as opsgenieTrigger.apxt and use this file in your Sales force configuration and let me know how it goes!

```
trigger opsgenieTrigger on Case (after insert, after update) {
string endpoint = <OPSGENIE_API_URL>;
Case obj = Trigger.new[0];

string id=obj.Id;
string ownerId=obj.OwnerId;
boolean isDeleted = obj.IsDeleted;
string caseNumber = obj.CaseNumber;
string contactId = obj.ContactId;
string accountId = obj.AccountId;
string assetId = obj.AssetId;
string parentId = obj.ParentId;
string suppliedName = obj.SuppliedName;
string suppliedEmail = obj.SuppliedEmail;
string suppliedCompany = obj.SuppliedCompany;
string suppliedPhone = obj.SuppliedPhone;
string typeOfCase = obj.Type;
string status = obj.Status;
string reason = obj.Reason;
string origin = obj.Origin;
string subject = obj.Subject;
string description = obj.Description;
boolean isClosed = obj.IsClosed;
string priority = obj.Priority;
datetime closedDate = obj.ClosedDate;
boolean isEscalated = obj.IsEscalated;
boolean isClosedOnCreate = obj.IsClosedOnCreate;
datetime createdDate = obj.CreatedDate;
string createdById = obj.CreatedById;
datetime lastModifiedDate = obj.LastModifiedDate;
string lastModifiedById = obj.LastModifiedById;
datetime systemModstamp = obj.SystemModstamp;
string contactPhone = obj.ContactPhone;
string contactMobile = obj.ContactMobile;
string contactFax = obj.ContactFax;
string engineeringReqNumber = obj.EngineeringReqNumber__c;
string product = obj.Product__c;
string potentialLiability = obj.PotentialLiability__c;
string opsgenieAlias = obj.opsgenie_alias__c;

string payload= '{'+
'\"id\" :' + opsgenieClass.getPayloadStringByHandlingNull(id)+ ',' +
'\"ownerId\" :' + opsgenieClass.getPayloadStringByHandlingNull(ownerId )+ ',' +
'\"isDeleted\" :' + opsgenieClass.getPayloadStringByHandlingNull(isDeleted)+ ',' +
'\"caseNumber\" :' + opsgenieClass.getPayloadStringByHandlingNull(caseNumber)+ ',' +
'\"contactId\" :' + opsgenieClass.getPayloadStringByHandlingNull(contactId)+ ',' +
'\"accountId\" :' + opsgenieClass.getPayloadStringByHandlingNull(accountId)+ ',' +
'\"assetId\" :' + opsgenieClass.getPayloadStringByHandlingNull(assetId)+ ',' +
'\"priority\" :' + opsgenieClass.getPayloadStringByHandlingNull(priority)+ ',' +
'\"parentId\" :' + opsgenieClass.getPayloadStringByHandlingNull(parentId)+ ',' +
'\"suppliedName\" :' + opsgenieClass.getPayloadStringByHandlingNull(suppliedName)+ ',' +
'\"suppliedEmail\" :' + opsgenieClass.getPayloadStringByHandlingNull(suppliedEmail)+ ',' +
'\"suppliedCompany\" :' + opsgenieClass.getPayloadStringByHandlingNull(suppliedCompany)+ ',' +
'\"suppliedPhone\" :' + opsgenieClass.getPayloadStringByHandlingNull(suppliedPhone)+ ',' +
'\"typeOfCase\" :' + opsgenieClass.getPayloadStringByHandlingNull(typeOfCase)+ ',' +
'\"status\" :' + opsgenieClass.getPayloadStringByHandlingNull(status)+ ',' +
'\"reason\" :' + opsgenieClass.getPayloadStringByHandlingNull(reason)+ ',' +
'\"origin\" :' + opsgenieClass.getPayloadStringByHandlingNull(origin)+ ',' +
'\"subject\" :' + opsgenieClass.getPayloadStringByHandlingNull(subject)+ ',' +
'\"description\" :' + opsgenieClass.getPayloadStringByHandlingNull(description)+ ',' +
'\"isClosed\" :' + opsgenieClass.getPayloadStringByHandlingNull(isClosed)+ ',' +
'\"closedDate\" :' + opsgenieClass.getPayloadStringByHandlingNull(closedDate)+ ',' +
'\"isEscalated\" :' + opsgenieClass.getPayloadStringByHandlingNull(isEscalated)+ ',' +
'\"isClosedOnCreate\" :' + opsgenieClass.getPayloadStringByHandlingNull(isClosedOnCreate)+ ',' +
'\"createdDate\" :' + opsgenieClass.getPayloadStringByHandlingNull(createdDate)+ ',' +
'\"createdById\" :' + opsgenieClass.getPayloadStringByHandlingNull(createdById)+ ',' +
'\"lastModifiedDate\" :' + opsgenieClass.getPayloadStringByHandlingNull(lastModifiedDate)+ ',' +
'\"systemModstamp\" :' +opsgenieClass.getPayloadStringByHandlingNull(systemModstamp)+ ',' +
'\"contactPhone\" :' + opsgenieClass.getPayloadStringByHandlingNull(contactPhone) + ',' +
'\"contactMobile\" :' + opsgenieClass.getPayloadStringByHandlingNull(contactMobile)+ ',' +
'\"contactFax\" :' + opsgenieClass.getPayloadStringByHandlingNull(contactFax)+ ',' +
'\"engineeringReqNumber\" :' + opsgenieClass.getPayloadStringByHandlingNull(engineeringReqNumber)+ ',' +
'\"product\" :' + opsgenieClass.getPayloadStringByHandlingNull(product)+ ',' +
'\"potentialLiability\" :' + opsgenieClass.getPayloadStringByHandlingNull(potentialLiability)+',' +
'\"opsgenieAlias\" :' + opsgenieClass.getPayloadStringByHandlingNull(opsgenieAlias)+
'}';

opsgenieClass.xRESTCall(endpoint ,payload);


}
```

Thanks,  
Connor


author: Mike Almon
body: Hi Connor,

Thanks for the response it looks like salesforce is now improperly passing the opsgenie, it looks like the dashes (-) are being dropped somewhere when the echo happens

Order of what I am seeing

1. New alert created in Opsgenie gets alias of 87becdae-5ff3-4b1f-b17d-33fe1a0ba44e-1637677705260
2. Salesforce creates new case with the text field opsgenie_alias populated with 87becdae-5ff3-4b1f-b17d-33fe1a0ba44e-1637677705260
3. Opsgenie creates new echo alert with alias of 87becdae5ff34b1fb17d33fe1a0ba44e1637677705260

Initial Opsgenie ticket:

![Screenshot from 2021-11-23 09-53-34.png](https://community.atlassian.com/t5/image/serverpage/image-id/170593i3C568E8E3B760BC5/image-size/large?v=v2&px=999 "Screenshot from 2021-11-23 09-53-34.png")

Salesforce Case Created:

![Screenshot from 2021-11-23 09-47-15.png](https://community.atlassian.com/t5/image/serverpage/image-id/170595iCFBC3C3FD421D405/image-size/large?v=v2&px=999 "Screenshot from 2021-11-23 09-47-15.png")

Opsgenie Echoed Ticket:

![Screenshot from 2021-11-23 09-54-04.png](https://community.atlassian.com/t5/image/serverpage/image-id/170596iDD7CB85590727112/image-size/large?v=v2&px=999 "Screenshot from 2021-11-23 09-54-04.png")


author: Connor Eyles
body: Hi [@Mike Almon](/t5/user/viewprofilepage/user-id/4643233)

Thanks for getting back to me! Are you able to raise a ticket on this one?

That way we can do a full investigation on the payload getting sent over from Salesforce to understand the issue at hand better.

You can go to <https://support.atlassian.com/> to raise the ticket, ensure to link this community link in the ticket and I will keep an eye out for you in our queue :)

Thanks,

Connor


author: Mike Almon
body: Hi Connor,

I found the issue that is causing the the drop dashes it is within the opsgenieClass.apxc that you provide, basically is filtering out all characters that are not alphanumeric or a space so I replaced
> \[\^a-zA-Z0-9\\\\s\]

with
> \[\^a-zA-Z0-9\\\\s\\\\-\]

at this line and it is now passing the opsgenie_alias propperly

<https://github.com/opsgenie/opsgenie-integration/blob/11dbd3f30e3fdf1d19caea22ad91d569d870d244/salesForceServiceCloud/opsgenieClass.apxc#L14>


author: Connor Eyles
body: Hey Mike,

Awesome find :)

I'll pass this onto the development team to fix up, appreciate you sharing your findings here!

Thanks,

Connor


Tags: cloud

salesforce