Today is my last day of training so I thought I'd try to build another chart capitalizing on some of the harder pre-work that was done yesterday. I'd like to try my hand at a radar chart sometime but with the time allotted, I took on the bubble chart. Here is the finished product. Similar to the bar chart, this chart is embedded in a vf page which passes to the Flex object the session id and the account id.
It has 3 data components per record:
X: StageName
Y: Probability
Radius: Amount
The chart could be useful for salesforce users to surface high value opportunities for a given account.
Lessons Learned:
I had this weird effect where my entire data area was plotted as orange. When hovering over the orange, I could see my two records and the related X, Y, and R attributes. I suspect that this was because my data elements had different data types. Only when I removed StageName from the plotted data did the orange block go away. The only thing that could resolve it was to create tags in my chart for the Horizontal and Vertical axis. Within these tags, I specified the category fields as StageName and Probability. Only after adding these tags did my bubbles plot as above. Here's the relevant section from the mxml:
<mx:BubbleChart
id="mybubblechart"
showDataTips="true"
>
<mx:horizontalAxis>
<mx:CategoryAxis title="Opportunity Stage" categoryField="StageName" dataProvider="{opps}"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:CategoryAxis title="User Probability" categoryField="User_Probability__c" dataProvider="{opps}"/>
</mx:verticalAxis>
<mx:series>
<mx:BubbleSeries
xField="StageName"
yField="User_Probability__c"
radiusField="Amount_Num__c"
fill="{sc1}"
stroke="{stroke1}"
dataProvider="{opps}"/>
</mx:series>
</mx:BubbleChart>
I think that there will need to be a good amount of data massaging done within salesforce for the data to be presented in some interesting ways. For now, this gives some perspective on LOE and feasibility.
Showing posts with label charts. Show all posts
Showing posts with label charts. Show all posts
Friday, October 29, 2010
Flex and Charts in Salesforce - Continued
As I was saying, the mashup reference that salesforce published is definitely old. The login object they refer to and some of the query syntax seemed to be no longer supported in Flex 4.
In the end, I used the same approach that the author did: hardcode initially to prove that login and query work. Then, parameterize to get the chart more business-ready.
Here's what I learned.
LoginBySessionId
Logging in by credentials (LoginbyCredentials) was very easy. The problem is I wanted this application to work from within an existing salesforce session and I didn't want the user to login again. I found that the session Id could be reused, however, LoginBySessionId was less obvious in implementation.
It took a few tries but after determining that I was getting the session Id, I started getting an error that I was not using the correct URL. To fix this, I just needed to set the url property to the value from my salesforce session:
app.serverUrl = parameters.surl;
app.loginBySessionId(parameters.sid);
So, putting this into a function:
private function init():void
{
_sid = parameters.sid;
_webWrapper=app.wrapper;
app.serverUrl = parameters.surl;
app.loginBySessionId(parameters.sid);
}
init() gets called from the property creationComplete on the Application tag.
Getting past the URL error, I started to get an error stating that my session id was invalid. A quick google search turned up this helpful community post which indicated that the global API session value that is used in the mashup guide is not a reliable way to get the session id. To get the correct session id, you have to write a controller extension and fetch the id for the user. Here's the link to the community thread:
http://forums.sforce.com/t5/Adobe-Flash-Builder-for-Force/Invalid-Session-Id-using-Flex/m-p/156531
Executing a Salesforce Query from Flex
The mashup guide shows the AsyncResponder approach to fetching data from salesforce. I could not use this method for my use case so I used the LoginResultEvent to invoke my query. The query comes back as an array so the only way I could see if my query was working was to use Alert.Show to show the contents. Here is the class that should be imported:
Where is the SWF file generated?
The Mashup guide complete skips this detail! The SWF gets generated in your working bin-debug folder. Just upload your SWF to the static resources in Salesforce to reference it in your VF page.
Debugging
Lots of use of Alert.Show to see what was going on. I never figured out the debugger but Alert.Show and the ObjectUtil class were a ton of help to see what I was getting and when.
Error 2032???
Many thanks to this blogger for posting this finding. The error was being thrown I don't think I would have ever found the fix for this error code:
http://blog.prasannadeshpande.com/2010/02/salesforce-flex-error-2032-stream-error-url/
In the end, I used the same approach that the author did: hardcode initially to prove that login and query work. Then, parameterize to get the chart more business-ready.
Here's what I learned.
LoginBySessionId
Logging in by credentials (LoginbyCredentials) was very easy. The problem is I wanted this application to work from within an existing salesforce session and I didn't want the user to login again. I found that the session Id could be reused, however, LoginBySessionId was less obvious in implementation.
It took a few tries but after determining that I was getting the session Id, I started getting an error that I was not using the correct URL. To fix this, I just needed to set the url property to the value from my salesforce session:
app.serverUrl = parameters.surl;
app.loginBySessionId(parameters.sid);
So, putting this into a function:
private function init():void
{
_sid = parameters.sid;
_webWrapper=app.wrapper;
app.serverUrl = parameters.surl;
app.loginBySessionId(parameters.sid);
}
init() gets called from the property creationComplete on the Application tag.
Getting past the URL error, I started to get an error stating that my session id was invalid. A quick google search turned up this helpful community post which indicated that the global API session value that is used in the mashup guide is not a reliable way to get the session id. To get the correct session id, you have to write a controller extension and fetch the id for the user. Here's the link to the community thread:
http://forums.sforce.com/t5/Adobe-Flash-Builder-for-Force/Invalid-Session-Id-using-Flex/m-p/156531
Executing a Salesforce Query from Flex
The mashup guide shows the AsyncResponder approach to fetching data from salesforce. I could not use this method for my use case so I used the LoginResultEvent to invoke my query. The query comes back as an array so the only way I could see if my query was working was to use Alert.Show to show the contents. Here is the class that should be imported:
- import mx.utils.ObjectUtil;
- Alert.show(ObjectUtil.toString(result));
Where is the SWF file generated?
The Mashup guide complete skips this detail! The SWF gets generated in your working bin-debug folder. Just upload your SWF to the static resources in Salesforce to reference it in your VF page.
Debugging
Lots of use of Alert.Show to see what was going on. I never figured out the debugger but Alert.Show and the ObjectUtil class were a ton of help to see what I was getting and when.
Error 2032???
Many thanks to this blogger for posting this finding. The error was being thrown I don't think I would have ever found the fix for this error code:
http://blog.prasannadeshpande.com/2010/02/salesforce-flex-error-2032-stream-error-url/
Thursday, October 28, 2010
Flex and Charts in SFDC
The second case that I wanted to try out was building a F3 web application for Salesforce. I tried to follow this mashup guide but again, the reference on the salesforce wiki seemed to be stale.
http://wiki.developerforce.com/index.php/Tutorial:_Creating_Flex_Salesforce_Mashups
It took some head pounding and a bunch of google searches but I eventually got it working in our org. More on this tomorrow!
http://wiki.developerforce.com/index.php/Tutorial:_Creating_Flex_Salesforce_Mashups
It took some head pounding and a bunch of google searches but I eventually got it working in our org. More on this tomorrow!
Subscribe to:
Posts (Atom)