• myztaken
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

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"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<body scroll="no" >
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="FlexSalesforce" width="100%" height="100%"
codebase="https://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<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"
flashvars="session_id={!API.Session_ID}&server_url={!API.Partner_Server_URL_140}&externalURL=https://na6.salesforce.com/resource/123XXXX89000/salesforceRSL"
loop="false" allowScriptAccess="always" type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</body>
</html>



The syntax of my page is:

<apex:page sidebar="true" showheader="true">
<apex:flash src="{!$Resource.Example5}" height="500" width="100%"
         flashvars="session_id={!$Api.SESSION_ID}&server_url={!$Api.Partner_Server_URL_140}&externalURL={!$Resource.salesforceRSL}"/>
</apex:page>

 

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;

                    connection.login(lr);
                }

 

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

loginWithSessionId(
 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:
(mx.messaging.messages::HTTPRequestMessage)#0
  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
(com.salesforce.results::Fault)#0
  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.

David



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,
Jeff
 
  • January 16, 2009
  • Like
  • 0
I faced INVALID_SESSION_ID  exception calling getUserInfo() of SalesforceAppExPartnerAPI.SforceService from my .net web service.


my code:
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
https://na6-api.salesforce.com/services/Soap/u/12.0/511500D80000000Kb2v

Code:

    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:

Code:

{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:
http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=518

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