• Faiza Iqbal
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I have implemented a simple integration with the help of platform events. The subscriber is an apex trigger that is working fine. And the updates from Salesforce are published in account's after update trigger. This after update trigger/ the event should be published only if the account was updated by some actual salesforce user, not with an automated process. But somehow the events are looped. The subscriber event receives an update/create a message, processes it and within 1 or 2 seconds the event is published back for the same record. I have added this check: 
//if user is automated process then it will create a recurssion
        if(UserInfo.getName() != 'Automated Process')
        {
AccountEventClass.InitializePublishEvent(newAccountList, oldMap);
        AccountEventClass.isRecurrsion = true;
}


But still, it is fired. I have deactivated the workflow rules but that did not help. Added debug logs on my AccountEventClass and on Account trigger but I don't see any logs. But still, the second party is receiving the messages back for the same records with 2 to 3 seconds.

Does anybody have any idea that how to find the process that might be triggering it? Or how to fix it? For example, the event should be published only if the account was updated by some actual salesforce user.

Many thanks!

Hi, I am new to the REST API in Salesforce. I have to POST a binary csv file to the 3rd party application and the given below is curl example:
curl --request POST \
     --header 'Authorization: Bearer <token> \
     --header 'Content-type: text/csv' \
     --header 'Accept: text/plain' \
     --data-binary @/myhome/salesdata-2018-03-26.csv \ 
     https://admin.testsite.com/hapi/merchant/<id>/sales-data/api
And here is my apex code:
String fileName = 'salesdata-' +date.today().Day() +'-'+ date.today().Month() +'-'+ date.today().Year()+'.csv';
        String targetURL = 'https://entufl5t6i91i.x.pipedream.net';
        
        // assemble the body payload
        String header = 'Content-Disposition: form-data; name="file"; filename="' + fileName + '"; Content-Type: application/octet-stream; ';
        String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
        String bodyEncoded = EncodingUtil.base64Encode(csvBlob);
        Blob bodyPayload = EncodingUtil.base64Decode(headerEncoded+bodyEncoded);
        
        // send out the request
        HttpRequest req = new HttpRequest();
        req.setBodyAsBlob(bodyPayload);
        req.setHeader('Authorization', 'bearer  hjghj');
        req.setHeader('Content-Type', 'text/csv');
        req.setMethod('POST');
        req.setEndpoint(targetURL);
        req.setTimeout(60000);
try
        {
            Http http = new Http();
            HttpResponse response = http.send(req);
            system.debug('response: ' + response);
            
        }
        catch(Exception e)
        {
            system.debug('e:' +  e);
        }


And the request bin URL is https://requestbin.com/r/entufl5t6i91i/1d4zZyJdIarNLef7Gq5SlveeRih
And it does not look right.

When I POST it to actual 3rd part application the response is 400 and the message is 'bad request'. Kindly point out what I am doing wrong here.

Many thanks!

I have implemented a simple integration with the help of platform events. The subscriber is an apex trigger that is working fine. And the updates from Salesforce are published in account's after update trigger. This after update trigger/ the event should be published only if the account was updated by some actual salesforce user, not with an automated process. But somehow the events are looped. The subscriber event receives an update/create a message, processes it and within 1 or 2 seconds the event is published back for the same record. I have added this check: 
//if user is automated process then it will create a recurssion
        if(UserInfo.getName() != 'Automated Process')
        {
AccountEventClass.InitializePublishEvent(newAccountList, oldMap);
        AccountEventClass.isRecurrsion = true;
}


But still, it is fired. I have deactivated the workflow rules but that did not help. Added debug logs on my AccountEventClass and on Account trigger but I don't see any logs. But still, the second party is receiving the messages back for the same records with 2 to 3 seconds.

Does anybody have any idea that how to find the process that might be triggering it? Or how to fix it? For example, the event should be published only if the account was updated by some actual salesforce user.

Many thanks!