Hi To Salesforce Devs,
Wednesday, 26 August 2015
Friday, 21 August 2015
MultiselectPicklist using Javascript - Visualforce page
Hi Salesforce Dev ,
Now I am going to demonstrate on the handling Multi select Pick list from Javascript on Visual force page.
Here is the code for the Multi select pick list ,
Here is the JS code , which will used to move left / right from Multi Select Pick list.
Thank you.
Haribabu Amudalapalli
Now I am going to demonstrate on the handling Multi select Pick list from Javascript on Visual force page.
Here is the code for the Multi select pick list ,
<table> <tr> <th ><h1 style="margin-left: 150px;">Account Fields</h1> </th> <th><h1 style="margin-left: 142px;">Contact Fields</h1> </th> </tr> <tr> <td> <apex:panelgrid columns="5" id="accpanel" style="margin-top: 10px;margin-left: 20px;"> <apex:selectList value="{!AccFields}" multiselect="true" size="5" id="accleft" style="width: 142px;height: 89px;"> <apex:selectOptions value="{!AccountFields}"/> </apex:selectList> <apex:panelGroup > <br/> <apex:Commandbutton value=" > " onclick="MoveToRight('{!JSINHTMLENCODE($Component.accleft)}','{!JSINHTMLENCODE($Component.accright)}','Account');return false;" rerender="frm"/> <br/><br/> <apex:Commandbutton value=" < " onclick="MoveToLeft('{!JSINHTMLENCODE($Component.accleft)}','{!JSINHTMLENCODE($Component.accright)}','Account');return false;" rerender="frm"/> <br/><br/> </apex:panelGroup> <apex:selectList id="accright" multiselect="true" size="5" value="{!AccountRightselected}" style="width: 142px;height: 89px;"> <apex:selectOptions value="{!RightAccountFields}"/> </apex:selectlist> </apex:panelgrid> </td> <td> <apex:panelgrid columns="5" id="conpanel" style="margin-top: 10px;margin-left: 20px;"> <apex:selectList value="{!Confields}" multiselect="true" size="5" id="conleft" style="width: 142px;height: 89px;"> <apex:selectOptions value="{!ContactFields}"/> </apex:selectList> <apex:panelGroup > <br/> <apex:Commandbutton value=" > " onclick="MoveToRight('{!JSINHTMLENCODE($Component.conleft)}','{!JSINHTMLENCODE($Component.conright)}','Contact');return false;" rerender="frm"/> <br/><br/> <apex:Commandbutton value=" < " onclick="MoveToLeft('{!JSINHTMLENCODE($Component.conleft)}','{!JSINHTMLENCODE($Component.conright)}','Contact');return false;" rerender="frm"/> <br/><br/> </apex:panelGroup> <apex:selectList id="conright" multiselect="true" size="5" value="{!ContactRightselected}" style="width: 142px;height: 89px;"> <apex:selectOptions value="{!RightContactFields}"/> </apex:selectlist> </apex:panelgrid> </td> </tr> </table>
Here is the JS code , which will used to move left / right from Multi Select Pick list.
function MoveToRight(leftpickval,rightpickval,type){ var removeOptions = new Array(); if(document.getElementById(leftpickval)!=null && document.getElementById(rightpickval)!=null){ var leftOptions = document.getElementById(leftpickval); var rightOptions =document.getElementById(rightpickval); var iCount=0; for(var i=0;i<leftOptions.options.length;i++){ if(leftOptions.options[i].selected){ if(rightOptions.options.length==1 && (rightOptions.options[rightOptions.length-1].value==null || rightOptions.options[rightOptions.length-1].value=='')) rightOptions.options[0] = new Option(leftOptions.options[i].text, leftOptions.options[i].value); else rightOptions.options[rightOptions.length] = new Option(leftOptions.options[i].text, leftOptions.options[i].value); removeOptions[iCount] = leftOptions.options[i].value; iCount++; } } for(var i=0;i<removeOptions.length;i++){ for(var j=0;j<leftOptions.length;j++){ if(leftOptions.options[j].value == removeOptions[i]){ leftOptions.remove(j); break; } } } } sortLeftSelect(leftpickval); sortRightSelect(rightpickval); } function MoveToLeft(leftpickval,rightpickval,type){ var removeOptions = new Array(); if(document.getElementById(leftpickval)!=null && document.getElementById(rightpickval)!=null){ var leftOptions = document.getElementById(rightpickval); var rightOptions =document.getElementById(leftpickval); var iCount=0; for(var i=0;i<leftOptions.options.length;i++){ if(leftOptions.options[i].selected){ if(rightOptions.options.length==1 && (rightOptions.options[rightOptions.length-1].value==null || rightOptions.options[rightOptions.length-1].value=='')) rightOptions.options[0] = new Option(leftOptions.options[i].text, leftOptions.options[i].value); else rightOptions.options[rightOptions.length] = new Option(leftOptions.options[i].text, leftOptions.options[i].value); removeOptions[iCount] = leftOptions.options[i].value; iCount++; } } for(var i=0;i<removeOptions.length;i++){ for(var j=0;j<leftOptions.length;j++){ if(leftOptions.options[j].value == removeOptions[i]){ leftOptions.remove(j); break; } } } } sortLeftSelect(leftpickval); sortRightSelect(rightpickval); } function sortLeftSelect(typeval) { var tmpAry = new Array(); selElem = document.getElementById(typeval); for (var i=0;i<selElem.options.length;i++) { tmpAry[i] = new Array(); tmpAry[i][0] = selElem.options[i].text; tmpAry[i][1] = selElem.options[i].value; } tmpAry.sort(); while (selElem.options.length > 0) { selElem.options[0] = null; } for (var i=0;i<tmpAry.length;i++) { var op = new Option(tmpAry[i][0], tmpAry[i][1]); selElem.options[i] = op; } return; } function sortRightSelect(typeval) { selElem = document.getElementById(typeval); var tmpAry = new Array(); for (var i=0;i<selElem.options.length;i++) { tmpAry[i] = new Array(); tmpAry[i][0] = selElem.options[i].text; tmpAry[i][1] = selElem.options[i].value; } tmpAry.sort(); while (selElem.options.length > 0) { selElem.options[0] = null; } for (var i=0;i<tmpAry.length;i++) { var op = new Option(tmpAry[i][0], tmpAry[i][1]); selElem.options[i] = op; } return; }
Thank you.
Haribabu Amudalapalli
Wednesday, 19 August 2015
Salesforce Collections
HI Salesforce Developers ,
Developer Console
list<college> lststudent=new list<college>();
College shadan=new college();
shadan.strStudentName='susan';
Shadan.iStudentAge=20;
lststudent.add(shadan);
Retrieving values from list
for(college obj:lststudent)
{
system.debug(obj.strStudentName);
system.debug(obj.istudentage);
}
Sets
set<college> setCollege=new set<college>();
creating an object
college biet=new college();
Inserting elements into set
biet.strStudentName='Jasmine';
biet.strStudentName='Jasmine';
biet.istudentage=24;
adding object to the set instance
setcollege.add(biet);
Retrieving elements from set
for(college obj:setcollege)
{system.debug(obj.strStudentName);
system.debug(obj.istudentage);
}
Maps
map<string,string> mapname=new map<string,string>();
mapname.put('anitha','Sfdc');
mapname.get('anitha');
DML Operations
Inserting values into Accounts Object
list<account> a1=new list<account>();
a1.add(new account(name='Preethi'));
insert a1;
15/10/14
Lists
list<string> lststring=new list<string>(); // creating an empty list of string
lststring.add('philomenal'); //adding element philomenal to the list
string str =lststring.get(0); //Retrieves the element at index 0
system.debug(lststring.get(0)); //printing the retrieved element
Inserting and retrieving multiple elements from List
list<integer> lstinteger=new list<integer>();
lstinteger.add(1000);
lstinteger.add(2000);
integer isalary =lstinteger.get(0);
isalary =lstinteger.get(1);
system.debug(lstinteger.get(0));
system.debug(lstinteger.get(1));
Sorting in Order
List<string> colors=new list<string>{'green','pink','red'};
colors.sort();
system.assertEquals('green', colors.get(0));
system.assertequals('pink',colors.get(1));
system.debug(colors.get(0));
system.debug(colors.get(1));
add(integer,object) method
list<integer> lstinteger=new integer[3];
lstinteger.add(0,1000);
lstinteger.add(1,2000);
lstinteger.add(3,3000);
system.assertEquals(lstinteger.get(3), 3000);
system.debug(lstinteger.get(3));
Coping one List elements into another list using addall()
List<Account>lsta1= new list<Account>([select name,id from account where name='hitachi']);
List<Account>lsta2=new list<Account>([select name,id from account where billingcity='hyd']);
List<Account>lstMasterAcc= new List<Account>();
lstMasterAcc.addall(lsta1);
//System.debug(MasterAcc.get(lsta1));
lstMasterAcc.addall(lsta2);
//system.debug(MasterAcc.get(lsta2));
for(Account Accobj:lstMasterAcc)
{system.debug(lstMasterAcc.get(0));}
Coping List elements into set using addall(set)
List<Account>lstacc=new list<Account>([select name,id from account where billingcity='hyd']);
set<account> setacc=new set<account>([select id,name from account where name='abcd']);
List<account> lstMasteracc=new List<account>();
lstmasteracc.addall(setacc);
lstmasteracc.addall(lstacc);
for(account objacc:lstmasteracc)
{
system.debug(lstmasteracc.get(0));
}
Inserted account records into list elements
List<account> LstAcc=new list<account>([select name,id from account where billingcity='hyd']);
for(account obj:lstacc){
system.debug(lstacc.get(0));
}
Clearing the inserted elements from List
List<account> LstAcc=new list<account>([select name,id from account where billingcity='hyd']);
//for(account obj:lstacc){
lstacc.clear();
//}
Clone()
List<account> lstacc=new list<account>([select name,id from account where billingcity='hyd']);
List<Account> lstAccClone= lstacc.clone();
system.debug('cloned account is '+lstacc);
Equals(list)
List<account> lstacc=new list<account>([select name,id,createddate from account where billingcity='hyd']);
List<Account> lstAccClone= lstacc.clone();
system.debug('cloned account is '+lstacc);
lstacc.equals(lstAccClone);
system.debug('lstacc equals lstaccclone '+lstacc.equals(lstAccClone));
Debug:18:43:50:248 USER_DEBUG [6]|DEBUG|lstacc equals lstaccclone true
Equals(list) for deep clone
List<account> lstacc=new list<account>([select name,id,createddate from account where billingcity='hyd']);
List<Account> lstAccClone= lstacc.deepclone(true,false,true);
system.debug('cloned account is '+lstacc);
lstacc.equals(lstAccClone);
system.debug('lstacc equals lstaccclone '+lstacc.equals(lstAccClone));
Debug:18:42:52:074 USER_DEBUG [5]|DEBUG|lstacc equals lstaccclone false
Get(integer)
list<integer> lstinteger=new list<integer>();
lstinteger.add(1000);
lstinteger.add(2000);
integer isalary =lstinteger.get(0);
isalary =lstinteger.get(1);
system.debug(lstinteger.get(0));
system.debug(lstinteger.get(1));
HashCode()
list<integer> lstinteger=new integer[3];
lstinteger.add(0,1000);
lstinteger.add(1,2000);
lstinteger.add(3,3000);
//system.assertEquals(lstinteger.get(3), 3000);
//system.debug(lstinteger.get(3));
lstinteger.hashcode();
system.debug(lstinteger.hashcode());
Debug: 18:50:56:050 USER_DEBUG [8]|DEBUG|1301808609
IsEmpty()
list<integer> lstinteger=new integer[3];
lstinteger.add(0,1000);
lstinteger.add(1,2000);
lstinteger.add(3,3000);
system.debug(lstinteger.isempty());
Debug: 18:53:31:034 USER_DEBUG [5]|DEBUG|false
list<integer> lstinteger=new integer[3];
//lstinteger.add(0,1000);
//lstinteger.add(1,2000);
//lstinteger.add(3,3000);
lstinteger.clear();
system.debug(lstinteger.isempty());
Debug : 18:55:42:034 USER_DEBUG [7]|DEBUG|true
Remove(integer)
list<integer> lstinteger=new integer[5];
//lstinteger.clear();
lstinteger.add(0,1000);
lstinteger.add(1,2000);
lstinteger.add(2,3000);
integer iremoveinteger=lstinteger.remove(0);
// for(integer iobj:lstinteger)
//{
system.debug('Contents of the list'+lstinteger);
Debug: 19:07:15:047 USER_DEBUG [10]|DEBUG|Contents of the list(2000, 3000, null, null, null, null, null)
Updating account record (try catch exception)
list<account> a=new list<account>();
a=[select id,billingcity,accountnumber from account where id='00190000014Vftk'];
a.add(new account(billingcity='hyd'));
a.add(new account(accountnumber=12345));
try{
update a;
}
catch(exception e)
{//system.debug(dml exception);
}
Maps
map<string,string> m=new map<string,string>();
m.put('ani','sfdc');
m.put('sonu','.net');
m.put('manu','mobile');
//System.debug(m.get('sonu')); //prints keys(sonu) corresponding value(.net)
set<string> s=m.keyset();
System.debug(m.keyset()); //Prints all elements
Map<ID,Contact> mapAcc=new Map<id,contact>([select id,name from contact ]);
system.debug(mapacc.values()); // prints values of contact
Map<ID,Contact> mapAcc=new Map<id,contact>([select id,name from contact ]);
system.debug(mapacc.keyset()); //prints keys of contact
Map<ID,Contact> mapAcc=new Map<id,contact>([select id,name from contact ]);
system.debug(mapacc.size()); //gives the size of contacts
copy list elements into map
list<account> lstacc=new list<account>([select id,name from account where billingstate='ts']);
map<id,account> maplst=new map<id,account>(lstacc);
system.debug(lstacc);
ContainsKey()
Map<ID,account> mapAcc=new Map<id,account>([select id,name,billingcity from account ]);
system.debug(mapacc.containskey('00190000016L7jx'));
EXCEL CONNECTOR FOR SALESFORCE
Introduction:
Sales force provides programmatic access to your organization’s information using a simple, powerful, and secure application programming interface, the Force.com Web Services API.
Any functionality regarding Excel Connector is available only if your organization has the API feature enabled. This feature is enabled by default for Unlimited, Enterprise, and Developer Editions. Some Professional Edition organizations may also have the API enabled.
The Office Toolkit version of the API provides a Component Object Model (COM) interface to developers who want to write client applications that use COM technology to access their organization’s Sales force data. The Office Toolkit is built on top of, and interacts with, an organization’s Sales force data via the API. The Office Toolkit acts as an intermediary between COM client applications and the API, handling certain tasks implicitly so that client applications are simpler to code.
Download And Install the Sforce Office Toolkit
- Click to download File- save.
- Extract the .zip folder into your preferred folder.
For Professional Edition users
- Under the download menu, click sforce_connect_pe_winter11.zip
- Open the Zip file,it has a .xla file contained within it.
- Open Excel and click on start button. Then click “Excel Options”.
- Select Add-Ins from the side menu in Excel options.
- In the bottom of the pane ,you should see a menu called “manage” with excel Add-Ins selected. Click Go.
- You should see the Add-Ins menu, Click Browse and navigate to the folder where you saved the .xla file.
- Select the .xla file and add it to the Add-Ins menu.
- You should noe see the SForce Connector Add-in as an available option in the Add-Ins menu.
- Click Ok in Excel. Click on Add-Ins tab to start using the connector
Login to Salesforce.com via the Connector
- Under the Add-Ins tab in Excel, Select “Table Query Wizard”.
- Enter your Salesforce.com credentials.
- Click Login.
Querying Saleforce Data
Once logged in the Wizard will walk you through the remaining steps needed to pull in data from your Salesforce instance.
Step 1: Indicate where in the Spreadsheet you want to put the data returned from the query. Click Next.
Step 2a: Choose the Table that holds the data you wish to analyze. Click Next.
Step 2b: Choose the Fields that hold the data you wish to analyze. Click Next.
Step 3: Add any conditions by which you want to filter the data before it is returned to Excel. When done, click Run Query.
The Data is queried from Salesforce and pulled into Excel. Depending upon the amount of data, this may take several minutes.
Once the data is returned you can use it as you would other Excel data to analyze, make pivot tables, charts, etc.
Update Data to org.
- We can even make modifications to the data queried, and update those values. Select the cells in which the modification is done.
- Under the Add-Ins tab in Excel, Select “Update Selected Cells”.
- You will get a pop-up saying:
- Click Ok
To Insert Data:
To insert a new row of data into salesforce.com
- Enter the new data for these records into the appropriate columns,
- To inform the connector that you would like to insert this row of data into salesforce.com, place the keyword new into the account ID column, as shown.
- To indicate the rows of data to be inserted, select one or more cells on the row which you would like to insert, the connector uses the currently selected row or rows to construct the insert Sforce function call. You may select multiple rows to be inserted.
- With the data in place, and the keyword new in the account ID column, you're ready to insert the row, click on the connector menu item Insert Selected Rows.
The API insert function call returns the account ID, which is place back in to the worksheet, in this example selected Cell is overwritten with the new account ID.
Subscribe to:
Posts (Atom)