You need to sign in to do that
Don't have an account?
Praetorian65
When I run it I get the error: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session
Message Edited by Praetorian65 on 01-07-2009 06:05 AM
Using Javascript to run apex from a VF page
I have a Visualforce page that contains a javascript function:
Code:
function reportSuccessOrFail() { try { var success = sforce.apex.execute("ReadResult","GetResult",{}); if(success ==true) alert('Salesforce data successfully updated'); else alert('There was an error with the update'); } catch (e) { alert(e.name + ' ' + e.message); } }
This uses the following apex class:
Code:
global class ReadResult{ webservice static boolean GetResult() { boolean returnresult = false; DateTime timefrom = DateTime.now(); DatabaseRequest__c[] dbr = [select Result__c from DatabaseRequest__c order by Time__c desc]; if(dbr.size()>0) { returnresult = dbr[0].Result__c; } return returnresult; } }
When I run it I get the error: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session
How do I fix this?
Message Edited by Praetorian65 on 01-07-2009 06:05 AM
I should also point out that the action completes before the apex script has finished processing. I have to wait for the script to finish before checking the database object.
Message Edited by Praetorian65 on 01-07-2009 08:02 AM
sforce.connection.sessionId = "{!$Api.Session_ID}";
I think you already have included the following script.
<script src="/soap/ajax/13.0/connection.js"/>