function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SpongeBob_2009SpongeBob_2009 

Apex Trx Sequence/Counter for Callout

Need a unique identifier(trx id) for a web service call out.  Any ideas?

 

 

The only thing I can think of involves using a custom object:

sql equiv example:  update table set lastid = lastid + 1  (creates a lock - and then select)

 

essentially:

 

obj seq = [Select nextId from obj];

seq.nextId = seq.nextId + 1;

update seq;

 

Integer trxId = seq.nextId;

 

Will this logic even work?  The counter code will reside within the 'callout' class.

WesNolte__cWesNolte__c

Hey

 

Yeah I think that's the gist of it. You'd have to create a 'control' custom object, and you could use the new 'custom settings' feature of Winter 10 to reference the field in question. I'm assuming the Id is used to track the transaction? So your process might be,

 

Control object has an autoincrement field, and perhaps some other fields for auditing or info.

Method that initiates callout creates a record in the control object, writing necessary info and using autoincrement field as the id.

// time passes

The id is passed to some other app or back to salesforce in a url/soap packet.

You check the id against the control object for whatever reason, and if teh transaction is complete delete the record(or not, depending on requirements).

 

Cheers,

Wes

sfdccoder1sfdccoder1

It'll not work as you cannot peform DML before callout.

BTW  if it did work you would need to locak the select 'for update' for thread security.

I'm looking for a solution for the same problem myslef. Did you find one?