I have some code that needs to be a local backup of key data from my Salesforce Instance's Schema. I want to alert my user any time the Salesforce (remote) schema slips out of sync with my local copy and prompt them to refresh the local copy.
I'm now pretty comfortable with the REST api via the excellent Rails restforce gem, but i'm struggling to come up with a speedy and elegant way to check for changes to my instance.
Initially I'd tried making a .describe
call (nb below client
is an object that contains and formats auth data)
Digest::MD5.hexdigest(client.describe) => cfa443badd87ee0578e812a007b1f303
ie, I get a call back from global describe, turn it into a string and make a checksum via MD5.
However, I've noticed since adding new fields to the instance the checksum doesn't change, seems that global describe doesn't hold any data on fields. So I tried a dynamic:
client.describe.map {|o| client.describe( o['name'] ) }
ie, do a global call, grab iterate through the objects and call an additional describe and grab all field data. I can then turn this back into a string and run it through my MD5 checksum... But this takes... AGES. Our instance has 300+ objects, this code takes +1 min to run.
Does anyone have a smarter, more efficient and quicker way to poll for changes to the schema via the REST API?
With my current implementation I'm able to tack it on at the start of already long running activities that depend on the schema's being in sync. It can then throw an error and suggest remediation if they're not... but ideally I'd have a nippy little bit of code I could use more widely to prompt the user via notices/flashes to take action from many different points within the app.
Anyone ever tried anything similar? Any ideas would be great!