Friday, February 20, 2009

Code to clone a opportunity of Contact

Clone a opportunity of cpntact using the Clone Function
Object required is Contact,Opportunity, OpportunityContactRole.

public Void CloneOpportunity() {
try{
//ArrayList to get the Checked opportunityId
String []idsArray= allIds.split(';');
if(idsArray.size()<0){
for(Integer i=0;i
Opportunity opp=[select Id,Name,StageName,CloseDate from opportunity where id =:idsArray[i]];
Opportunity newOpp = opp.clone(false, true);
newOpp.Name=opp.Name+'_Clone';
insert newOpp;
//making a entry in OpportunityContactRole object
OpportunityContactRole opportunityRole = new OpportunityContactRole();
opportunityRole.OpportunityId=newOpp.Id;
opportunityRole.ContactId=System.currentPageReference().getParameters().get('id');
insert opportunityRole;
}
}throw new MyException();
}catch(MyException e){
string Msg = 'plz select a Opportunity';
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,Msg ));
return null;
}
return null;
}

AJAX And SalesForce

The AJAX a JavaScript wrapper around the API:

The AJAX available for any organization that has API access.
The AJAX Mozilla Firefox and Internet Explorer 6 or 7.
The AJAX is based on the partner WSDL. Because there is no type
checking in JavaScript, the type information available in the enterprise WSDL
is not needed.
You can execute any call in the API, and access any API object that you
normally have access to.
You can issue asynchronous calls, and use callback functions to handle the
results. For more information, see API Calls and the AJAX Toolkit.
You can use header options with a different syntax than in the API. For more
information, see Using Headers with the AJAX Toolkit.
You can handle errors with the AJAX Toolkit. For more information


AJAX And SalesForce


This document explains how to use AJAX Toolkit in JavaScript with embedded
API calls in an s-control.
An s-control is an HTML page that is rendered within the Apex platform user
interface layer. This is accomplished by creating a portion of the user interface
using an IFrame and publishing your HTML page in that IFrame. There are
very few restrictions on what can be contained in the HTML that is hosted by
that IFrame. You can run JavaScript, embed ActiveX or Java applets, or even
Flash.Whatever is appropriate for an HTML page is generally acceptable as an
s-control.With the AJAX Toolkit, you can create an s-control page that contains
API calls and processes Salesforce data.


Sample S-Control Using the AJAX
This s-control
queries data and displays it on the same tab where the s-control resides. For more information about creating or editing s-controls



If you create an s-control with the content above, then execute the s-control by either clicking a custom link that activates it
or by placing it on a tab other than the Home tab, you will see a few rows of unformatted data displayed in a new window.

Wednesday, February 18, 2009

Diffrence SAX between DOM

Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.
SAX parser.................................
1.
Parses node by node.
2.
Doesn’t store the XML in memory.
3.
We cant insert or delete a node.
4.
Top to bottom traversing.
5.
SAX is an event based parser
6.
SAX is a Simple API for XML.
7.Import class

import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

8.
doesn’t preserve comments
9.
SAX generally runs a little faster than DOM.


whereAS...............................................DOM


1.
Stores the entire XML document into memory before processing
2.
Occupies more memory.
3.
We can insert or delete nodes.
4.
Traverse in any direction.
5.
DOM is a tree model parser.
6.
Document Object Model (DOM) API.
7.Import class
import javax.xml.parsers.*;
import org.w3c.dom.*;

8.preserves comments
9.
SAX generally runs a little faster than DOM.