• myztaken
  • 0 Points
  • Member since 2009

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 4

Hi there..


I'm trying to  call an Apex WS from my Flex application. When I use this way... Assuming that session is an active connection with SF using the Connection class from the flextoolkit...



public function loadPowerChart(oppId:String, callback:AsyncResponder):void { var powerChart:PowerChart; loadPowerChartCallback.context.clientCallback = callback; var executeParams:Object = { className: "OptimizerWS", methodName: "loadPowerChart", args: [new Parameter("oppId", "0068000000MsLwM")], callback: loadPowerChartCallback, nameSpace: "optimizer" }; session.execute(executeParams); }

Everything works fine, and im getting my Custom object back as I expected...


But when I send the object from flex to Apex I cant find a way to make it so...


Im trying the following:



public function savePowerChart(oppId:String, callback:AsyncResponder, powerChart:PowerChart):void { savePowerChartCallback.context.clientCallback = callback; var sfPowerChart:SObject = powerChart.toSObject(); trace(sfPowerChart.toDebugString()); var executeParams:Object = { className: "OptimizerWS", methodName: "loadPowerChart", args: [new Parameter("powerChart",sfPowerChart)], callback: savePowerChartCallback, nameSpace: "optimizer" }; session.execute(executeParams); }


 And the toSObject on my PowerChart flex has the following code inside...



public function toSObject():SObject{ var sfObject:SObject = new SObject('optimizer__SO_Power_Chart__c'); sfObject.optimizer__Optimizer_ID__c = this.id; return sfObject; }


 The Trace from the toDebugString() on the SObject prints the following...



SObject type:optimizer__SO_Power_Chart__c optimizer__Optimizer_ID__c:23D0FB27-C4F9-B5D3-163F-FB7D44FCD302


And the error displayed on my callback is the following...



Unexpected element {http://soap.sforce.com/schemas/class/optimizer/OptimizerWS}type during simple type deserialization


 And my saveProbabilityChart WS method is the following...



webservice static List<String> savePowerChart(SO_Power_Chart__c powerChart){ System.debug('Entering loadPowerChart: Chart=>'+powerChart);//+' oppId=>'+oppId); List<String> errors = new List<String>(); System.debug(powerChart); return errors; }


... I don't really know the correct way to do it... But I know that someone in here could help me arround...


Thanks in advance...:manhappy:


~ foe









I have created a Flex component that I've now deployed as both an S-Control and a Visualforce page.  The Flex code attempts to use the session id and server url for logins. These values are passed in as Flash variables. When this code is invoked from the S-Control the login succeeeds.  However the login fails when invoked from the Visualforce page. (I can also login with username and password from the page).

The html body for the S-Control:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<body scroll="no" >
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="FlexSalesforce" width="100%" height="100%"
<param name="movie" value="{!Scontrol.JavaArchive}" />
<param name="quality" value="high" /><param name="play" value="true" />
<param name="bgcolor" value="#f3f3ec" />
<param name="allowScriptAccess" value="always" />
<param name="flashvars"
value="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_140}" />
<embed src="{!Scontrol.JavaArchive}" play="true" bgcolor="#f3f3ec"
width="100%" height="700" name="FlexSalesforce" align="middle"
loop="false" allowScriptAccess="always" type="application/x-shockwave-flash"

The syntax of my page is:

<apex:page sidebar="true" showheader="true">
<apex:flash src="{!$Resource.Example5}" height="500" width="100%"


Within my Flash component, the following code snippet gets called:


               var connection:Connection = new Connection();

                var sessionId:String = Application.application.parameters[SESSION_ID];
                var serverUrl:String = Application.application.parameters[SERVER_URL];
                if (sessionId != null && serverUrl != null)
                    LOG.debug("Using session id for login");
                    lr.server_url = serverUrl;
                    lr.session_id = sessionId;
                    loginResponder = new AsyncResponder(loginCallback);
                    lr.callback = loginResponder;

                    //connection.protocol = "https";   //tried with and without setting these
                    //connection.serverUrl = serverUrl;



I've noticed that the sessionId's are different for the page vs. the S-Control even though they are invoked from the same browser moments apart. I've also noticed that the URLs for the control use "https://na6.visual.force.com" vs. "https://c.na6.visual.force.com" for the page.

I'm seeing the following output in my logs for the page case:


Starting login
Using session id for login

 sid: 510600  [....]  _p4DIBpWrGf
 surl: https://c.na6.visual.force.com/services/Soap/u/14.0/510600D80000000ZTCY
App Domain = c.na6.visual.force.com
Api Server name = c.na6.visual.force.com
_internalServerUrl = https://c.na6.visual.force.com/services/Soap/u/14.0/510600D80000000ZTCY
loading the policy file: https://c.na6.visual.force.com/services/Soap/cross-domain.xml
Your application must be running on a https server in order to use https to communicate with salesforce.com!
invoke getUserInfo
intServerUrl is null
intServerUrl = https://c.na6.visual.force.com/services/Soap/u/14.0/510600D80000000ZTCY
_invoke getUserInfo
'0078EE29-37C1-427B-78E0-AE6DF3EE2F28' producer set destination to 'DefaultHTTPS'.
Method name is: getUserInfo
'direct_http_channel' channel endpoint set to http://c.na6.visual.force.com/resource/1235576467000/
'0078EE29-37C1-427B-78E0-AE6DF3EE2F28' producer sending message 'B769C4FE-87A6-A2E6-F4DA-AE6DF3FD5ABB'
'direct_http_channel' channel sending message:
  body = "<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="urn:partner.soap.sforce.com"><sfns:SessionHeader><sessionId>510600D80000  [...]        dDV1hVMr_p4DIBpWrGf</sessionId></sfns:SessionHeader></se:Header><se:Body><getUserInfo xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com"/></se:Body></se:Envelope>"
  clientId = (null)
  contentType = "text/xml; charset=UTF-8"
  destination = "DefaultHTTPS"
  headers = (Object)#1
  httpHeaders = (Object)#2
    Accept = "text/xml"
    SOAPAction = """"
    X-Salesforce-No-500-SC = "true"
  messageId = "B769C4FE-87A6-A2E6-F4DA-AE6DF3FD5ABB"
  method = "POST"
  recordHeaders = false
  timestamp = 0
  timeToLive = 0
  url = "https://c.na6.visual.force.com/services/Soap/u/14.0/510600D80000000ZTCY"
'0078EE29-37C1-427B-78E0-AE6DF3EE2F28' producer connected.
Method name is: getUserInfo
'0078EE29-37C1-427B-78E0-AE6DF3EE2F28' producer acknowledge of 'B769C4FE-87A6-A2E6-F4DA-AE6DF3FD5ABB'.
responseType: Fault
Saleforce Soap Fault: sf:INVALID_SESSION_ID
INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session
  context = (null)
  detail = (Object)#1
    UnexpectedErrorFault = (Object)#2
      exceptionCode = "INVALID_SESSION_ID"
      exceptionMessage = "Invalid Session ID found in SessionHeader: Illegal Session"
      xsi:type = "sf:UnexpectedErrorFault"
  faultcode = "sf:INVALID_SESSION_ID"
  faultstring = "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"
Error: Ignoring policy file requested from https://c.na6.visual.force.com/crossdomain.xml because a cross-domain redirect to https://na6.salesforce.com/crossdomain.xml occurred.
Warning: Domain c.na6.visual.force.com does not explicitly specify a meta-policy, but Content-Type of policy file https://c.na6.visual.force.com/services/Soap/cross-domain.xml is 'text/x-cross-domain-policy'.  Applying meta-policy 'by-content-type'.


Thanks in advance for your help.


I am trying to call a Visualforce page from a custom list button.  I have done this successfully from a detail page button by creating a page using a standard controller for the detail object, selecting Visualforce page as the content source and then picking the page I wanted from the pull down list for content.
However, I can't seem to get this to work for a list button.  I pick the list button option on the custom button or link page, and pick visualforce page for the content source, but I don't get my visualforce page to appear in the content pull down list.
Is there something I'm doing wrong?
As an adjunct question, should I be using the standard controller for the detail object being displayed at the top of the page or for the objects being referenced in the list (in the case I'm working on now, the objects in the list are the same object as the detail object and reference back to the detail object)? 
I understand that one of the benefits of using a visualforce page in this manner is that the id for the detail object is automatically passed to the visualforce page, thereby making data display easier on the detail page.  If a visualforce page can be invoked from a list button, what object id is passed?  That of the detail item at the top of the page?
Thanks in advance for your help,
  • January 16, 2009
  • Like
  • 0
I faced INVALID_SESSION_ID  exception calling getUserInfo() of SalesforceAppExPartnerAPI.SforceService from my .net web service.

my code:

SalesforceAppExPartnerAPI.GetUserInfoResult userInfoResult = Binding.getUserInfo();

 Binding is property where _authHeader.EXTSessionID and _authHeader.EXTServerLocation are values passed to web service from salesforce portal.
_autHeader.ExtSessionID value retrieved via apex code : UserInfo.getSessionId() and _authHeader.ExtServerLocation is


    private SalesforceAppExPartnerAPI.SforceService Binding {
            get {
                    try {                        

                        // binding
                        SalesforceAppExPartnerAPI.SforceService binding = new SalesforceAppExPartnerAPI.SforceService();
                        // by setting these values, we are essentially logged in to the API as this user
                        binding.SessionHeaderValue = new SalesforceAppExPartnerAPI.SessionHeader();
                        binding.SessionHeaderValue.sessionId = _authHeader.EXTSessionID;
                        binding.Url = _authHeader.EXTServerLocation;

                        return binding;
                    } catch (System.Web.Services.Protocols.SoapException exsoap) {
                        if (exsoap.Code.ToString().Contains("API_DISABLED_FOR_ORG")) {
                            throw new EXTAPIAuthFail("This edition of salesforce.com does not provide API access."
                                + "API access is a standard feature of Enterprise "
                                + "and Unlimited Editions.<br>"
                                + "Certify your application to gain API access to "
                                + "Professional Edition as well.<br><br>", exsoap);
                        } else {
                            throw new EXTAPIAuthFail("SoapException: Unable to validate incoming web call.", exsoap);
                    } catch (System.UriFormatException uriEx) {
                        throw new EXTAPIAuthFail("The Server URL is invalid. " + uriEx.Message, uriEx);
                    } catch (Exception e) {
                        throw new EXTAPIAuthFail("Unable to connect to the API. " + e.Message, e);
                } else {
                    return _binding;

Exception Stack trace:


{System.Web.Services.Protocols.SoapException: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at Mindflash.SalesforceAppExPartnerAPI.SforceService.getUserInfo()


It works fine before salesforce introduced winter9 release and version 14.0 API.
It's super easy to call an apex webservice method from the ajax toolkit, since it very helpfully provides the sforce.apex.execute method.

I assumed there would be something equivalent in the flex toolkit, but I can't find anything, and then stumbled across this thread from a few months ago:

Is this still the state of affairs?  If so, sounds like not only is it not easy to call an apex method from flex, but no-one has yet figured out how to do it.  (or at least hasn't figured it out and then replied to the forums.)

Seems like that can't be right, but I can't find anything anywhere (forums, docs, object structure within flex builder, etc.) to suggest otherwise.

Is anyone calling apex webservice methods from Flex, and if so, how?

Thanks much!

  • December 02, 2007
  • Like
  • 0