+ Start a Discussion
mattpick1mattpick1 

javascript trigger for apex code...

Hi,

 

I have a piece of javascript that I include in the head of the VF page using the <apex:includescript> tag and a static resource. It is listening for an event, which when detected causes a function to fire. In the old S-Control version there would then be some database operations using the connection.js library but from what I can gather this is the wrong way to go about it now with VF.

 

So my question is how can I hook in apex code to do my database operations? I want to completely stop using connection.js, but the trigger must be contained in the javascript in a static resource...

 

Thanks

 

Matt

TehNrdTehNrd
What event does your javascript listen for and what does it do? You should be able to convert this entirely to apex.
mattpick1mattpick1

There is a javascript api for an embedded flash object that I can't change...I implement the function:

event(msgObj, msgType)

Periodically the flash object fires the function. Depending on what the msgType is I add different bits of data on the msgObg into the salesforce database. This worked fine using sforce.connection.create but I've realised that I'm supposed to stop using that now that everything is being ported to VF pages.

 

Can you think of a way I can still interact with the DB?

 

Thanks

 

Matt

mattpick1mattpick1

Or....do we have to completely stop using connection.js or will it in the future still be allowed?

XactiumBenXactiumBen

You should be able to use an actionFunction to replace the javascript function that does the database updates.

 

<apex:actionFunction name="nameOfOldJSFunction" action="{!dodatabasestuff}" />

 

Just create a method in your controller that does the database updates and call it from the action function's action attribute.