Saturday 18 June 2011

Websocket API in HTML 5


Before discussing the Web Socket APIs in HTML 5 specifications lets have a look at the main point of the client-server architecture it is trying to address. The client-server communication over the Internet has seen changes over a period of time. This change has been from stateless communication to WebSockets.
 
Stateless communication
 
This is the first generation of client-server communication over the internet. 
    1. The client (web browser) sends a request to the server.
    2. Server processes this request and sends the result back to the client.
    3. Client will refresh the entire page.
Most of the web sites still work on this model even today (If not fully then certainly partially).

Ajax - The Asynchronous Way of Client-Server Communication
 
An Ajax application can send data to the server asynchronously and does not require a page refresh when receiving the data. Just a section of the page can be refreshed.
This brought a lot of change in the UI of websites and the way the user interacts. I remember Google was most particular in using AJAX in its websites.
AJAX was not a new programming language but just a new way of using JavaScript. The JavaScript object XMLHTTPRequest allows web pages to submit a request to the server in the background and define a JavaScript function on the client side to receive the response of that request. This function can then refresh the selective sections of the page based on server response.

Comet
 
Comet is a technique (and this technique has multiple implementations) which allows a server to push data to the client even when the client has not requested the data.
But this is not purely server-push. The client will have to make a specific request to the server, which indicates the server to long hold the request and later the server can push data to that client.
It may be achieved by opening a persistent HTTP session between a client & a specific server. But the problem is that HTTP1.0 specification does not allow a browser to open more than 2 simultaneous HTTP connections with the server. If one of them is blocked for a comet event then the browser usability may be impacted.
There are multiple other techniques to achieve comet connections.
 
Limitations with above techniques:
  • Still requires the client to initiate the request. 
  • There is no way for the server to inform the client about some change. The comet application tries to overcome this by opening a persistent session between the client and server. But it will keep a large strain on the server.
  • The techniques required to deal with Firewalls are very complex.
Polling technique
 
It can be done in two ways.
 
1. The client sends a request to the server after every few seconds to see if the data is ready or not. If the data is ready then the server will respond with the data and the client will not make further calls, otherwise the server will respond with an empty reply and the client will continue polling.
Higher rate of unnecessary server request
2. Make a single request to the server but keep the connection open unless we receive a response from the server.
Many thousand open connections need to be handled by the server. Server may not respond to the new clients requesting connections.

Web Sockets
  • Create a single bi-directional connection between client & Server. It means that the client can send a request to the server and forget; when the data is ready at the server the server will send it to the client.
  • Native to the browser which makes them light weight and easy to implement.
  • Uses its own protocol thus can tunnel thru firewalls and proxy with no extra effort. i.e Client does not use HTTP request but when a new WebSocket connection is established, then browser establishes the HTTP connection with the server and then upgrade that connection to a dedicated WebSocket connection setting a tunnel passing thru firewall and proxies.
  • Once the connection is established (as above) it is a two way channel on which client and server can communicate.
Creating a WebSocket is as easy as the code below
 
 var ws = new WebSocket("ws:<URL>");

Once the connection is established there are methods to control sending data and monitoring the connection.
ws.onopen = function(){ } // Connection Open 
ws.onmessage = function(){ } // received update
ws.onopen = function(){ } // Connection Close
//Funtions of WebSocket Object
ws.send(<text>);
ws.close();

Advantages:
  1. Since the Firewall is bypassed the streaming is very easy and can be done thru any connection.
  2. Don't need separate connection for up-stream and down-stream.
  3. Can be used with any client like AIR & Flex which comes with JavaScript support.
Limitations:
  1. Not all browsers support WebSockets as of now.
To see which Browser supports which feature of HTML5 you may refer to this link in wikipedia.. It however talks about the support in terms of a layout engine which is an engine used to render the UI in the browser. Though you can easily determine which Browser uses which layout engine. Let me also provide it here for quick reference.
BrowserLayout EngineComments
Internet ExplorerTrident / MSHTML(DLL)IE 8.0 = Trident4.0 = MSHTML DLL (8.0
FirefoxGeckohttp://en.wikipedia.org/wiki/Gecko_(layout_engine)
ChromeWebkithttp://en.wikipedia.org/wiki/WebKit
Safariwebkit
 

Sunday 12 June 2011

use Google API for show the line graph

PHP code----

$sql="select * FROM xyzreport where device_id='XYZ'";
$exe=mysql_query($sql);
$num=mysql_num_rows($exe);
if($num>0){
$x = $y = $z = array();
while($result=mysql_fetch_array($exe,MYSQL_ASSOC))
{
$x[] = $result['xplus'];
$y[] = $result['yplus'];
$z[] = $result['zplus'];
}
}

$script = '';
echo $script;


HTML:


<script src="https://www.google.com/jsapi" type="text/javascript">
</script>
<script type="text/javascript">
//call function to load graph using google api.
createGraph(newArrX, 'chart_divX', 'X axis');
createGraph(newArrY, 'chart_divY', 'Y axis');
createGraph(newArrZ, 'chart_divZ', 'Z axis');

function createGraph(arrVal, loadGraphDivId, titleAxis) {
google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Year');
        data.addColumn('number', 'vehcile');
        data.addRows(4);


for (loop=0; loop < arrVal.length; loop++)
         {
data.setValue(loop, 1,arrVal[loop]);
}

var chart = new google.visualization.LineChart(document.getElementById(loadGraphDivId));
        chart.draw(data, {width: 450, height: 300, title: titleAxis});
      }
}
 
</script>



<div id="chart_divX">

</div>
<div id="chart_divY">

</div>
<div id="chart_divZ">

</div>
</div>







how to convert php array into javascript?

$x = $y = $z = array();
while($result=mysql_fetch_array($exe,MYSQL_ASSOC))
{
$x[] = $result['xplus'];
}



$script = '';
echo $script;

Friday 10 June 2011

Easy NSString substring

Sadly, creating a simple substring in Objective-C isn't quite as obvious as in other languages. Here's a basic method to grab a substring of a given string before a defined character, in my case the ":" character:

NSRange end = [_contentsOfElement rangeOfString:@":"];
[myVar setName:[_contentsOfElement substringWithRange:NSMakeRange(0, end.location)]];

If you wanted grab a string between two characters, you could do:

NSRange start = [_contentsOfElement rangeOfString:@"|"];
NSRange end = [_contentsOfElement rangeOfString:@":"];
[myVar setName:[_contentsOfElement substringWithRange:NSMakeRange(start.location, end.location)]];

Default UITableViewCell font, and how to change it?

The default font is... Helvetica! If you want to change the size of the font, you can use:

cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];

You can also change the font using the above statement with a different font name.

Changing UITableViewCell text colors

This is a really easy but, but may not be immediately apparent. Personally, I first tried changing the color of the cell directly, then tried changing the color of the text within the cells. What you actually need to do is change the textColor property of the UILabel's that are inside of the cell. For example, if you want to change the color of the textLabel, you would use:

cell.textLabel.textColor = [UIColor lightGrayColor];

The same goes for the detail label if you are using that type of cell:

cell.detailTextLabel.textColor = [UIColor blackColor];

Saturday 4 June 2011

salesforce 401 Certification exam

These are the only types of questions for those folks who wish to appear for 401 certification

1. In Data loader 50,000 more records CRUD at a time
True
False

2. ID's are identical in
Production, full copy sandbox, developer
Production and full copy sandbox only
Production , developer
None

3. Maximum No of Master Details per child object
0
1
2
3
4

4. For the user object what can you do in the page layout
custom link
inline vf page
custom button
custom field

5. For approval process what groups can you have
profiles
roles and subordicates
active team members
None

6. In Page Layout can you add inline vf
True
False

7. What does out of the box salesforce give you?
data warehouse
approval process
workflow rules
validation rules

8.

A developer wants to ensure that when a parent record is deleted, child records are not deleted. Which relationship should the developer choose?
lookup
master-detail
many-to-many
master-to-master
None

9. Which statement is true about a custom tab?
It can only be included in one application.
It can only be included in standard applications
It can be included in as many applications as desired.
It can only be included in custom applications

10.

- When would a developer use upsert and external IDs?

(Choose two answers.)
To integrate with an external system
To migrate customizations from sandbox to production
To load related records without knowing Salesforce record IDs
To use the Force.com API to query for data

11. A group of executives has requested a convenient way to see daily metrics without having to log in to Salesforce. How would a developer accomplish this goal?
the users’ home page layouts to include a dashboard
Create a Workflow rule that sends a link to the dashboard in an email.
. Schedule the dashboard for daily refresh and email distribution.
Create a series of daily recurring events providing the dashboard link

12.

Within a custom recruiting application, Universal Containers uses a custom Position object to track positions. Positions expire 90 days after they have been approved. A Workflow Rule is in place to send an email to the hiring manager listed on a position 15 days before the expiration date. What will happen if the expiration date of a position is extended by 30 days?
An email will be sent 15 days before the original expiration date
An email will be sent 15 days before the updated expiration date
An email will be sent on the original expiration date
An email will not be sent

13. If you want the a list of positions what dashboard would you use
metric
table
chart
gauge

14.

Time-dependent workflow will not work with which type of workflow evaluation criteria

Only when a Record is created
Every time a record is created or edited
Every kind of workflow evaluation criteria
When a Record is edited and it did not previously meet the rule criteria

15. Which of the following is a standard Profile?
Sales User
Marketing User
Invoice Manager
Contract Manager

Date Formats and Date Literals in SOQL Query

Hi.. Welcome back..
I always had issues with SOQL Query utilizing dates in particular. So I wanted to share some tips and tricks on writing SOQL queries using some Built in Date Functions...

Now you do your query in 2 ways:

1. Specify a date in your query such as
Select Id,CreatedDate from Account where CreatedDate=DateValue(2008-02-05)
This will return all Id's for all the Account Object that were Created 2008-02-05.

2. Do it with a Fixed Expression or Built in Function such as:
Select Id, CreatedDate from Account where CreatedDate = YESTERDAY
This will return all Id's for the Account Object that were Created yesterday.
This is called a Date Literal.

Now before we go on:
You must know the Syntax for Date in Force.com :

YYYY-MM-DD

For DateTime the Syntax is as follows:

YYYY-MM-DDThh:mm:ss+hh:mm 2009-02-24T23:01:01+01:00
YYYY-MM-DDThh:mm:ss-hh:mm 2009-02-24T23:01:01-08:00
YYYY-MM-DDThh:mm:ssZ 2009-02-24T23:01:01Z

So Lets go into Date Literals: I took this off from the Salesforce.com Api docs...
The link is: http://www.salesforce.com/us/developer/docs/api/index.htm

Go to search and type in Date Literals... This should come up.(See Below)

Moving an existing field with data to another object (Salesforce Data Loader)

OK, so you have to move an existing field on one of your objects to another object, but the existing field values are sensitive data that cannot be lost.

Well, so far, saleforce has not come up with a feature to "move" the field with it's values... But these are the nessicary steps to preform the action, so I'm going to show you how it's done.


NOTE The original objects Records must be related to the other objects Records with a custom relationship field (EX: Accounts with Contacts) in order for this to work. Unless, you want the values from the field to be enterd as record names for an object, otherwise there is no way for salesforce to recocnize/map out where to put your data.

Overall Explanation: (Step 1) First we are going to create a new field on the object we want to "move" this field over to, and typically name it the same as the existing field were moving (to keep it simple), but you can rename it.

(Step 2) Then we are going to run a report of all existing field values for that field and the related objects ID (The object that you wish to move the field to). Export the report to Microsoft Excel, and put it in the correct format.

(Step 3) Then use the salesforce "Data Loader" to import(update) the data on the new field you created, mapping it by the desired objects ID. Once we have done this we will have accomplished our goal of moving the field.

(Step 4) is deleting the old field.

SO! here we go... Just as an example this time we are going to be moving a field from a custom object, which records are related to the records of the opportunities, to the opportunity page.

[Step 1]

Create the new field on the desired object you wish to move this field to, typicly to keep it simple you could name it the same as the existing field on the object were moving it from. In my case, the field on my custom object called "PV to client" which is a Picklist (drop-down), will be moved to the opportunity page, so im going to create a new Picklist field on my opportunity page called "PV to Client", same field type.
[Step 2]

Now we need to run a report, to gather all of the Data needed for this transfer. Reffering back to my example, Each opportunity in my system is related to one of my custom objects Records, the object i wish to transfer this feild from, which is named Successor borrower(s). You need to select the report type that includes the two related objects. This shouldn't be a problem if the objects records are related with a custom relationship field, and should also show up as a Report type, maybe in "Other" reports.

Now all i need to pull into my report are two fields...


Field #1 being: Opportunity Object: "Opportunity ID"



Field#2 being: Successor Borrower Object: "PV To Client"



NOTE On step #5 of making the report I selected the (Successor Borrower Object) field: PV to Client = Not equal to Null (blank). This insures that we will only pull in "PV to CLient" fields that are NOT blank. It's Cleaner...





Once you have run your report, this is what it should look like. Now i cut it short, but this report actually had 487 values in "PV to Client" that I need to transfer. If you notice, my field "PV to Client" is a picklist Field type, but note this process works for all data types weather it be dates, currencies, percentages, ect...





(SAVE THE REPORT)

Ok, so just one more step on step #2, exporting this report to Excel, which is very simple. Simply click "Export Details on the top of your report page.

Salesforce Will then prompt you to select the file format, you can either choose: "Comma Delimited.csv" -or- "Excel Format.xls".

If you have some manual editing you would like to preform before the import on the field values I would suggest choosing the "Excel Format.xls". After you have made any modifications to the values, save the Excel file as a "Comma Delimited.csv". I suggest renaming it upon saving as a csv, for example "temp_import1", this way if you made a mistake you can always go back to the original XLS file and make your changes, instead of overwriting the file. In our next step of importing these values back into salesforce were going to use a program made by salesforce called the "data Loader", which only accepts CSV files.


If the report and values look fine, just how you would like to move them, I suggest choosing "Comma Delimited", because in our next step as i mentioned above, in using the data loader, it requires the File to be a CSV, so it makes things a tad bit easier.


NOTE Reference the picture above of the Salesforce report, remove the old object name from the field name on the report, but only once it is in excel, so in my case it would only read the field name "PV To Client", not "Successor Borrower: PV To Client"


[Step 3]

Using the Salesforce Data Loader to import the field values into our newly created field

note The Salesforce "Data Loader" is FREE. To get it, log into Salesforce.com and go to Setup. There, go to Data Management->AppExchange Data Loader and click the Download link.

Click HERE for the "Data Loader User Guide", the best page reference for what were doing now would be page #7.

OK, now that you have the Data Loader we can begin with the importing process, step 3. when you open data loader you will be prompted with these options... [View 1]

If you have already seen this view upon downloading the application and exploring it you might see another view, that would look like this: [View2]


Either way, we are going to "update" the records on the object, since the new field we created already exists. I wont get to much into using the Data loader on this tutorial, just what we need it for right now.

NOTE This is a salesforce Application, built by Salesforce, it is safe, but be aware that any changes made by the data loader cannot be reversed, they are permenant.

If you are prompted with the first screen view, select update and provide it with your login information.

If you are prompted with the second view, go to [file->Update->Provide Login Info->Next

Ok, So now we are all on the same view, [view 2]

From there go to: File->Update-> (Select the object which you created the new field in.)

Then Browse for the CSV format file you have prepared->Click next. The Data Loader will then make you aware the exact amount of records you will be effecting. ->click "OK"

Now for the mapping, this part tells Salesforce where to put these field values, that's why our report contained the new object records Id's, and the value of the field we wish to "transfer" over. If you have followed my instructions and read everything in this tutorial so far, this process will be very easy otherwise errors may occur.

From this screen click "create or Edit a Map"




Once you have done that it will take you to the "mapping Dialog" screen with will allow you to map out the fields so salesforce Data Loader Knows what to do with your data. You can either click and drag the correct salesforce fields down to match your spreadsheet values, or click "Auto-Match Fields to Columns", and again, if you have followed the tutorial clicking auto match will automatically match the fields you intended on matching, for you.



If your with me at this point, great, we're almost finished.
Click "OK" once you approve of the fields that are shown to be mapped.
Click Next if everything looks OK
Click Finish if everything looks OK

Now the update is in progress, depending on the amount of records this can take anywhwere from 5 seconds to 10 minutes.

Go to the new field you wished to populate with those existing values from the related object to see if everything looks good, which I'm sure it does. This is to ensure the update went smoothly, the data has been properly "moved".

That's it, congratulations, there is also so much more you can do with the Salesforce Data Loader, play around with it a little bit, but remember, nothing is reversable.

I hope this tutorial was helpful to you, and I look forward to making more tutorials for common sales force administrator requests and issues. After all, there is always something new to learn bout Salesforce, on all levels.

Any questions or comments are greatly appreciated!

Creating Custom Fields and all about their purposes ?

During this Tutorial I'll walk you through all of the different data types along with any personal information I can provide you about them from personal experiance. Ok, so to begin, just to be clear, you must be a Salesforce Administrator to create any fields so you may not be able to view alot of the pages i'll be discusing.

Creating fields: To start go to Setup->App SetupOK, once your at the "App Setup" you have a choice to make. Create this new field in a custom object? or Create this new field in a standard salesforce object (EX: Opportunities, Accounts, Contacts, Leads)Whichever you choose, here is how to preform the action of creating a new custom field for both.
___________________________________________________________________ Standard Object: Setup->App Setup->Customize->(Choose the object)->Fields
What You are looking at now is the "Fields" page for that object. From the top, you will see a list of the standard Salesforce Fields which could be anywhere from 5- 25-30 fields. They are non-editable but can be taken off of that objects view, so your users don't have to see them, if you find them useless.Towards the bottom is where your "custom" fields are, the section will read "Custom Fields & Relationships"Select "new", this is where the process begins, I'll explain more after i explain the Custom Objects direction to this point.
_____________________________________________________________ Custom Object: Setup->App Setup->Create->Objects
What You are looking at now is the "Custom Objects" list, which will contain (if you have any yet) all of your custom objects. Lets Say you already have at least one Custom Object, click on the object name (EX: Custom Object- "Taxes"). As you can see the layout is a lot different here compared to the standard salesforce object page. But since this Tutorial is about creating fields i wont get into the surrounding features you see and skip straight to what we came here for. The third section down you will see a section entitled "Custom Fields & Relationships", Select "new", this is where the proces begins...
___________________________________________________________________

After you Select "new", you will be prompted to select the (Field Type) of the field you wish to create. Now we will go through all of the different field types.

"Auto Number" Salesforce Definition: (A system-generated sequence number that uses a display format you define. The number is automatically incremented for each new record.) This field is typicaly used as a record name (Automatic Master Key) generator, EX: A company deals with thousands of customers and cannot track them by name, to avoid duplicate records, auto number would be a perfect solution.

"Formula" Salesforce Definition:(A read-only field that derives its value from a formula expression you define. The formula field is updated when any of the source fields change.) This field will not show up on the object unless a value is present, but this field is very useful. EX: A buisenes, which is tracked on opportunities collects a total of three different fee's. I can put a formula field in place to add each fee amount to the total collected fees, every time one of my fee fields is updated by one of my users. Formula fields have much more capability though, you can design your own custom math formulas that work off of multiple fields to provide you with a simple, effortless view of certain finances. It can calculate values from Date fields to, currency fields,percentages and even text fields.

("Lookup Relationship") Salesforce Definition: (Creates a relationship between two objects so you can associate two records with each other. A lookup relationship creates a field that allows users to click a lookup icon and select another record from a popup window.) This Field Is Perhaps one of the most important fields to think about when it comes to the future of your company, your saleforce system, report writing, Dashboards, Ect... EX: Every Account is related to a contact through a "lookup Relationship", therefore we can make reports including field information from both objects. When you create a new custom object, you are going to need to run reports including field information from the custom object to the object#2 that you related it to. With custom reporting you can run reports including information from up to 4 different objects, but only if they are tied with a "lookup Relationship", that is the importance of this field.

"Master-Detail Relationship" Salesforce Definition: Creates a required ("Master-Detail") relationship with another object. This allows users to click a lookup icon () and select a value from a pop-up list. You specify the related object that sources the items in the list. This Field shares the same importance as the "Lookup Relationship" field, except the difference betweeen the two is this one is used as a master. EX: Accounts->Opportunities->Contacts, the right place to place this field would be in accounts, the master object of the relationships.

"Checkbox" Salesforce Definition: Allows users to select a True (checked) or False (unchecked) value. This Field Type can be used for multiple reasons but can be replaced by other field types, while in the process capturing better data. EX: Payment Received [Checkbox {True-or-False}], OK that works but then we would want to create a date Field to capture payment date, right? So why not create a date field called "Date Payment Received" and track the date and if the payment was received or not, at the same time. Like i said before, this field has its uses but can be used as a shortcut, unnoticably, Resulting in Data Duplication.

"Currency" Salesforce Definition: Allows users to enter a dollar or other currency amount and automatically formats the field as a currency amount. This can be useful if you export data to Excel or another spreadsheet. These fields are useful for tracking a company's financial Data, and can be used with "formula" Fields, to calculate Dollar/Euro amounts due to whatever the company's needs may be.

"Date" Salesforce Definition: Allows users to enter a date or pick a date from a pop up calendar.

"Date/Time" Salesforce Definition: Allows users to enter a date and time, or pick a date from a pop up calendar. When users click a date in the pop up, that date and the current time are entered into the Date/Time field. This field is only necessary if the specific time as well as the date needs to be tracked, otherwise a standard date field would do the trick.

"email" Salesforce Definition: Allows users to enter an email address. The entered address is validated to ensure that it is in the proper format. Users can then click on the field to automatically launch their email program and send an email to that address. As the Salesforce definition mentioned, email Applications (apps) are available for many purposes. Some workflow rules you can build in Salesforce have the ability to send emails to specific people or users, when certain field information is triggered, setup b the administrator. Also Mass Email applications can pull from your "email" fields, weather it be leads or contacts and mass blast marketing campaigns, working off of this field.

"Number" Salesforce Definition: Allows users to enter any number. Leading zeros are removed. Ex: Number of Item "192" purchased = (2), this field has a million possibilities.

"Percent" Allows users to enter a percentage number, for example, 10 and automatically adds the percent sign to the number.

"Phone" Allows users to enter any phone number. Automatically formats it as a phone number. This is a crucial field no matter what the business, everybody has contacts right? but, there are some very well designed Call-Center Applications designed for salesforce by third party companies that marketing companies find very useful.

"Picklist" Salesforce Definition: Allows users to select a value from a list you define. EX: If a Company deals with three banks for there transactions, one for each deal (Opportunity). The ideal field to track this data would be a picklist. a Picklist field is also known as a dropdown, giving you options to select from, but the user cannot add his/her own values, of course it can be done but only by the administrator.

"Picklist (Multi-Select)" Salesforce Definition: Allows users to select multiple values from a list you define. A Multi-Select Picklist is not to much different than a regular picklist, except for the fact that users can choose multiple values from the picklist, vs just one with your average picklist.

"text" Salesforce Definition: Allows users to enter any combination of letters and numbers.

"Text Area" Salesforce Definition: Allows users to enter up to 255 characters on separate lines.

"Text Area (Long)" Salesforce Definition: Allows users to enter up to 32000 characters on separate lines.

"URL" Salesforce Definition: Allows users to enter any valid website address. When users click on the field, the URL will open in a separate browser window.

That raps it up as far as the different types of Salesforce Fields available. If there is any advice I Can give you, it is to watch out for data duplication, like i mentioned in my own words on the description of the "checkbox" field, and if anything Ive written today has inspired you to try a new idea, take advantage of your salesforce Sandobox.

Every salesforce Account is also given a Sandbox, that is where you can test your applications and new data tracking ideas, in a safe environment, without putting your company's data at risk.

Any Feedback, questions are greatly appreciated.