Could not subscribe to salesforce with API_VERSION 48 from restforce

150 Views Asked by At

I am currently subscribing for 2 topics one for Account and another for Contacts. I am successfully able to subscribe to both topics with api_version 26 (default version used by restforce), but I don't get events for delete actions with this api_version.
Gems used:

gem 'cookiejar', git: 'https://github.com/MissionCapital/cookiejar.git'  
gem 'faye', '0.8.9'
gem 'restforce', '~> 4.2.2'

code:

@client = Restforce.new(username: ENV['SF_USERNAME'],
                        password: ENV['SF_PASSWORD'],
                        security_token: ENV['SF_SECURITY_TOKEN'],
                        client_id: ENV['SF_CLIENT_ID'],
                        client_secret: ENV['SF_SECRET_ID'])

PushTopic

@client.create!('PushTopic',
                                ApiVersion: '48.0',
                                Name: ENV['CONTACT_PUSH_TOPIC_NAME'],
                                Description: 'all contact records',
                                NotifyForOperations: 'All',
                                NotifyForFields: 'All',
                                Query: 'select Id, FirstName, LastName, Title, Email, Phone, MobilePhone, OtherPhone, AccountId, OwnerId, IsDeleted from Contact')

This results in the client being in version with 26.0 of the salesforce.

NOW, change to salesforce api_verison 48.0

@client = Restforce.new(username: ENV['SF_USERNAME'],
                        password: ENV['SF_PASSWORD'],
                        security_token: ENV['SF_SECURITY_TOKEN'],
                        client_id: ENV['SF_CLIENT_ID'],
                        client_secret: ENV['SF_SECRET_ID'],
                        api_version: '48.0')

Pushtopic

@client.create!('PushTopic',
                                ApiVersion: '48.0',
                                Name: ENV['CONTACT_PUSH_TOPIC_NAME'],
                                Description: 'all contact records',
                                NotifyForOperationCreate: 'true',
                                NotifyForOperationUpdate: 'true',
                                NotifyForOperationDelete: 'true',
                                NotifyForOperationUndelete: 'true',
                                NotifyForFields: 'All',
                                Query: 'select Id, FirstName, LastName, Title, Email, Phone, MobilePhone, AccountId, OwnerId, IsDeleted from Contact')

For this client, it doesn't receive any events. not for any actions (create, update, or delete).

Issue filed on Github. link: https://github.com/restforce/restforce/issues/537

1

There are 1 best solutions below

1
SahSantoshh On

Answer: We need to use replay for working with higher versions. It doesn't subscribe without replay.

 EM.run do
   @client.subscription "/topic/topicName", replay: -2  do |message|
     puts message["sobject"]
  end
 end