Browse Author: prashant.wayal

Mixed DML Exception in salesforce

Hi All, Many times we face this “Mixed DML Exception” in salesforce error while updating records. This error means you are updating setup and non-setup objects simultaneously. Here you will get details about all setup objects which cannot be inserted/updated with non-setup objects.

How can you avoid this?

To Avoid this type of error you use @future methods. Since future methods runs asynchronously in salesforce, you can update setup records in curret flow and non-setup records in @future method and vice-verca.

How to test Scheduled Apex Jobs in Salesforce

Hi All,

We can test this by scheduling the apex class to run after 2 or few minutes, but salesforce UI allows scheduling apex on per hour basis. So, to overcome with this problem we can use below code which will schedule apex class as per the time we set. Please follow the steps below:

1. Open Developer console and click on debug option.

2. Click on Open Execute anonymous window.

3. Write below code to it:

String str =‘ss mm HH dd MM ? yyyy’);

System.schedule(‘Send Message’, str , new your_ClassName());

4. Click on Execute button.

And thats it. You have successfully scheduled the apex class to run in 2 minutes. You can change the time as you want.


Custom charts using visualforce page

To generate custom charts by using visualforce page, just go through this simple demo:

//Visualforce code:

<apex:page controller=”PieChartController” title=”Pie Chart”>
<apex:chart height=”350″ width=”450″ data=”{!pieData}”>
<apex:pieSeries dataField=”data” labelField=”name”/>
<apex:legend position=”right”/>

// Apex controller code

public class PieChartController {
public List<PieChartData> getPieData() {
List<PieChartData> data = new List<PieChartData>();
data.add(new PieChartData(‘SUN’, 30));
data.add(new PieChartData(‘MON’, 15));
data.add(new PieChartData(‘TUE’, 10));
data.add(new PieChartData(‘WED’, 20));
data.add(new PieChartData(‘THU’, 18));
data.add(new PieChartData(‘FRI’, 8));
data.add(new PieChartData(‘SAT’, 10));
return data;
// Wrapper class
public class PieChartData {
public String name { get; set; }
public Integer data { get; set; }
public PieChartData(String name, Integer data) { = name; = data;
//Output for this demo
Chart Demo output

Add Products list to Activities i.e. Events and Tasks

Many of you want to add products lists to Events or Tasks because it is very important to have products list on Events or Tasks page layout so that if any of your sales person makes a call or mail to you, he should be able to give the list of products requested or sale. So, to have this functionality, please see the below screenshots;

  1. Add button on Task or Event Page layout as shown below:

Add Products Button

2. After adding button, click on this button and you will redirected  to a page, where you can select the products for adding in Activities as shown below:

Select Products to add on Activities

3. Once you have selected the products, those products will appear on that Activity page layout  as shown below:

Products List on Activity Page layout


If you want full source code for this, please contact us at



Get records using Salesforce Partner WSDL in .net


If you want to fetch the records from Salesforce object’s by using Partner WSDL in .net
then use this code. It also fetch the number of records available in Salesforce custom
and standard object.

Step 1 : Create new Web-service project in .net

Step 2 : Add your Partner WSDL  in your new project. For detail instruction Click here

Steps 3 :  Add new Item to your project and name it as “test.aspx” and add following code to it:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using sforce;

public partial class login : System.Web.UI.Page
NanoDictionary rbm = null;
SforceService bind = null;
String tableName, whrval, whrval1, likeQuery, simpleQuery;
List<String> lst = null;
protected void Page_Load(object sender, EventArgs e)
String uname = “”;
String pass = “Password+SecurityToken”;
String ur = “”;
rbm = new NanoDictionary(uname, pass, ur);
//Login to Salesforce
bool bl = rbm.loginSample();
Response.Write(“Login Success: ” + bl + “n”);
lst = new List<string>();
tableName = “Lead”;
whrval = “al”;
whrval1 = “Male”;
likeQuery = lst.ElementAt(2) + ” Like ‘%” + whrval + “%'”;
simpleQuery = lst.ElementAt(1) + ” = ‘” + whrval1 + “‘”;
//Call Method to get record count
int rec = rbm.getRecordsCount(tableName, simpleQuery+” or “+likeQuery);
if (rec > 0)
Response.Write(“Number Of Records: ” + rec+”<br>”);
Response.Write(“No Record found<br>”);
//Fetch Records
String name, gender, eml;
if (bl == true)
bind = rbm.binding;
QueryResult qres = rbm.getRecords(tableName, lst, simpleQuery+” or “+likeQuery, 2, 10, false);
if (qres != null)
//Convert & show Result
Response.Write(“<br>Table Name: <b>” + tableName);
Response.Write(“<table border = ‘0’ width=’50%’>”);
Response.Write(“<th align=’left’> Name </th>”);
Response.Write(“<th align=’left’> Gender </th>”);
Response.Write(“<th align=’left’> Email </th>”);
for (int j = 0; j < qres.records.Length; j++)
sforce.sObject obj = qres.records[j];
name = obj.Any[0].InnerText;
gender = obj.Any[1].InnerText;
eml = obj.Any[2].InnerText;
Response.Write(“<tr><td width=’15%’>”);
Response.Write(“</td><td width=’10%’>”);
Response.Write(“</td><td width=’15%’>”);
Response.Write(“<font color=’red’>Query parameter: ” + rbm.inputQry);
Response.Write(“</font><br>Please check Syntax for query parameter”);

Step 4: Create a c# class in this project and name it “NanoDictionary” and paste following code in it.

using System;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using sforce;
using System.Collections.Generic;

public class NanoDictionary
//Other Variables
public String username, password, url, inputQry;
public SforceService binding;
QueryResult qres;

public NanoDictionary(String username, String password, String url)
this.username = username;
this.password = password;
this.url = url;
//Method to count records
public int getRecordsCount(String tableName, string query)
int size = 0;
String qry = "select Id from " + tableName;
if (query != string.Empty)
qry += " where " + query;
qres = binding.query(qry);
size = qres.size;
catch (Exception ex)
//In case of any error -1 would be returned.
Console.Write("ex: " + ex);
size = -1;
//For succesful execution, return no. of records.
return size;
//Method to check if requested fields are available in specified object
public bool checkFields( String tblname, List fldlst)
Field[] flds = null;
bool chk = true;
List tempList = new List();
DescribeGlobalResult dgr = binding.describeGlobal();
DescribeGlobalSObjectResult[] dgsor = dgr.sobjects;
DescribeSObjectResult dsor = binding.describeSObject(tblname);
if (dsor != null)
flds = dsor.fields;
for (int i = 0; i < flds.Length; i++)
IEnumerable check = fldlst.Except(tempList);
if (check.Count() != 0)
chk = false;
catch (Exception e)
System.Diagnostics.Debug.WriteLine("Error: " + e.Message);
return chk;
//Method to login in salesforce
public bool loginSample()
Boolean success = false;
// Create a service object
binding = new SforceService();
LoginResult lr;
lr = binding.login(username, password);
// Save old authentication end point URL
String authEndPoint = url;
// Set returned service endpoint URL
binding.Url = lr.serverUrl;
binding.SessionHeaderValue = new SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
success = true;
if(success == true)
GetUserInfoResult userInfo = lr.userInfo;
System.Diagnostics.Debug.WriteLine("User Name: " + username);
System.Diagnostics.Debug.WriteLine("UserID: " + userInfo.userId);
System.Diagnostics.Debug.WriteLine("User Full Name: " + userInfo.userFullName);
System.Diagnostics.Debug.WriteLine("User Email: " + userInfo.userEmail);
catch (Exception e)
System.Diagnostics.Debug.WriteLine("An unexpected error has occurred: " +e.Message + "n" + e.StackTrace);
return success;
public QueryResult getRecords(String tableName, List fldName, String query, int skip, int take, bool more)
binding.QueryOptionsValue = new sforce.QueryOptions();
binding.QueryOptionsValue.batchSize = 250;
binding.QueryOptionsValue.batchSizeSpecified = true;
String qry = "select ";

//Check the fields are available in specified object
bool chk = checkFields(tableName, fldName);
if (chk == false)
return null;
List fldlist = new List();
for (int i = 0; i < fldlist.Count(); i++)
qry += fldlist[i] + ", ";
qry = qry.Substring(0, qry.Length - 2);
qry += " ";
qry += "from " + tableName;

if(query != String.Empty)
qry += " where " + query ;
qry += " limit " + take;
inputQry = qry;
System.Diagnostics.Debug.WriteLine("qry: " + qry);
bool tt = true;
qres = binding.query(qry);
catch (Exception er)
//If Query is not in correct format, return false.
Console.Write("er: " + er);
tt = false;
if (tt == true)
Console.Write("tt: " + tt);
return qres;
return null;


Unable to edit Visualforce page and Apex classes

Many of you are not able to edit your visualforce page or Apex class in any browser i.e. you are getting a page like this image

Error on Editor



To exit from this problem, just delete all your browsers cache and browsing history. After that just click on edit button and you will able to edit your pages and Apex classes.



No matching Contacts or Leads in Salesforce

Hi All,

many of you are using Salesforce for Outlook functionality provided by

Salesforce to integrate your outlook with Salesforce.

But many users are facing a problem such as

No matching Contacts or Leads in Salesforce” in the Side Panel of Salesforce in outlook.

I have found some of the reasons for this cause and listing here some of them.

1. This error occurs when your email id, contact name are not match with Salesforce contact name and email id.

2. Another reason for this is due to Outlook version you are using.

3. The owner of the Salesforce contact is not same as user of outlook.

4. The last but most important is “Salesforce does not support” POP3 and IMAP email servers.


To solve this issue please try one of the following solution.

1. Check your Contact name and Email Id from Salesforce so that it is exact matching with

outlook email id of person of whose record you want to view.

2. Try to use correct version of outlook  i.e  it should be compatible with Salesforce for outlook software.

3. Make sure the owner of Salesforce contact must be same as the user who is using outlook.

4. Close your outlook and start it again, this may help.

5. Check your mail server for outlook, if it is POP3 or IMAP, then change it to another one.

if the problem still remains then contact with Salesforce support team.


Hope this solution help you.


Get related list without Action Column in visualforce page


When you want to display related list on visualforce page, you can use <apex:relatedList>
tag, and it is very easy for ex:

<apex:page standardController="MyMasterObject__c">
	<apex:relatedList list="MyChildObjects__r" />

but this will display all the columns from related list including “Action” column and many times
we don’t want to display this column.

so to access your related list in the visualforce page without adding columns such as “Action“;
for example to access your products from Opportunity Page then use <apex:repeat> or <apex:dataTable>
tags from visualforce. for example here is a code to access your Estimate products which is related list
on Estimate page from visualforce page:

<apex:dataTable value="{!Estimate__c.EstimateOrder__r}" var="eorl">
<apex:column headerValue="Product" width="10%">
<apex:outputText value="{!eorl.Product_Code__c}"></apex:outputText>
<apex:column headerValue="Width" width="10%">
<apex:outputText value="{!eorl.Width__c}"></apex:outputText> </apex:column>
<apex:column headerValue="Height" width="10%">
<apex:outputText value="{!eorl.Height__c}"></apex:outputText> </apex:column>

This above code will display all your related list values on visualforce page without any column such as “Action
in a list.
To use <apex:repeat> replace <apex:dataTable> with <apex:repeat> and other fields are same.

Hope this will helpful for you.




Custom Send Email button on custom Objects


If you want to add a custom button to send email on custom object then follow below mentioned


1. Create Custom button on custom object;

2. in the content source, select URL;

3. in the value section, add following url{!Estimate__c.Bill_To_NameId__c}&rtype=003&doc_id=00Pi0000000OluX&retURL=/{!Estimate__c.Id}?srPos=0&srKp=00T

where Estimate__c.BillToNameId__c is the contact Id to whom you want to send email


Estimate__c.Id is the return URL of your custom object


Transfer objects, classes, pages from one org to another org in Salesforce


Here are the steps to transfer the Objects(Standard/Custom), Classes, Pages, Tabs, etc from one Salesforce organization to another with having different users.

1. Open IDE and create a new Project from source org.

2. While creating project select the components you want to transfer manually.

3. After completion, select either one object/Class/Page or as many you want ;

4. Then right click on it –> select IDE –> Deploy to Server;

5. Enter the login details for Destination org along with Security token

6. Then Select Archive Option where you want to store ZIP file for the selected Items to be Archived –> click Next;

7. On deployment plan page, Click Next

8. If you get “Success” as result then click on Finish button and thus you will be success in transferring the Objects/Classes/Pages etc from one Org to other, but if you get an Error message then try to remove that errors and try again the above mentioned steps.


  • 1
  • 2

Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box