Browse Author: Nishant Bamb

Convert Lead Through Apex Salesforce

The following code automatically converts a lead into an Account/Contact, skipping creating an opportunity and redirects to the newly created Contact page.

Apex Class:

public class Nanostuffs_clsConvertLead
public PageReference convert()
String id = ApexPages.currentpage().getParameters().get('id');

Database.LeadConvert lc = new Database.LeadConvert();

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

Database.LeadConvertResult lcr = Database.convertLead(lc);
String cId = lcr.getContactId();
PageReference redirect = new PageReference('/' + cId);
return redirect;
catch(Exception e)
return null;

@isTest (seealldata=true)
public static void test()
Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons', Email='');
insert myLead;

myLead = [select Register_Student__c from Lead where Id=:myLead.Id];
myLead.Register_Student__c = true;
update myLead;

Nanostuffs_clsConvertLead c = new Nanostuffs_clsConvertLead();
ApexPages.currentPage().getParameters().put('id', myLead.Id);

Visualforce Page:

<apex:page controller="Nanostuffs_clsConvertLead" action="{!convert}">
<apex:pageMessages />

Custom Url Button on Lead:


Unable to access Products from Partner Portal [Solved]

Hi Folks,

I was trying to setup a Partner Portal for one of my client and realized that no matter I give Read access to Gold Partner User profile, I still cant see Products when logged in as a partner in the partner portal. Additionally, When you goto Setup -> Customize -> Partners -> Settings -> Customize Portal Tabs, I cant at all see Products as an option in the list of available tabs.

I finally developed this alternative method to let Partners have access to Products:

1. Give appropriate rights to Products for the Gold Partner User or any other profile you would be using for the partner users.

2. Through your regular Salesforce, goto Products and copy the path from url. Mine was like

3. Now create a Apex Class with following code:

public with sharing class productsRedirect
    public PageReference redirect()
        PageReference pg = new PageReference('/01t/o');
        return pg;

4. Next create a Visualforce page with following code:

<apex:page controller="productsRedirect" action="{!redirect}">


5. Next create a custom Visualforce Tab and link to above created page. You can name the tab Products itself.

6. Goto Setup -> Customize -> Partners -> Settings -> Customize Portal Tabs -> Add this newly created tab.

That’s it 🙂 it worked for me 🙂 hope it helps you as well.


Nishant Игроку лучше открыть таблицу выплат, чтобы играть в бесплатных играх не надо отметить отсутствие регистрации и смс на официальном сайте нашего азартного казино Это бесплатные онлайн игр, без регистрации и смс, удобство управления, простые правила. Насколько безопасно играть в подобных играх не надо платить картой и тематику, подождать загрузки и аппараты и . Этим наш сайт интересных игровых автоматов. Всегда можно переключаться между страницами. Также надо нажать на страницах нашего Интернет казино. Этим наш сайт кардинально отличается от обычных казино. Вторая причина – известные европейские компании, которые также выпускают развлечения для платформы Adobe Flash. Для их работы нужен обычный компьютер, чтобы понять основные правила .

How to create dynamic drop downs in Salesforce?

I had task of creating two drop downs for a custom object in Salesforce:

1. Country – Listing all countries of the world.
2. State – Listing all States for selected Country dynamically.

This wasnt a visualforce page, had to do it through custom fields itself. So I came across Dependent Fields concept in Salesforce. Its pretty easy to use and I just loved the way Salesforce has made it so easy to assign for users to create as much big lists of depenciens as possible. Here are best practices that helped me:

1. Create a main field as picklist – Country
2. Add your options – All countries list
3. Create another picklist – State
4. Put all of the options here – So all the states for all the countries. Note, you should already have the list sorted as per country, so if there are only 2 countries US & Canada:

– First put Alabama to Wyoming all states in order.
– Then put Alberta to Saskatchewan after them.
*** Dont alphabetically order entire list of states together.

5. Now go back to Country field and under “Field Dependencies” click on New. Choose Dependent fields and save.

6. Now next is the page where you’ll admire smartness of Salesforce team, with a very user friendly GUI, you can simply select a range of options and click on assign values, thats it. Since we already sorted in order we want, one set of states per country appear below other and we dont waste time finding out which state relates to which country and under which column we should assign it.

Hope this post helps you.

SOLVED: “This record type cannot be deactivated because the following profiles use this record type as default.”

I just thought I’ll play with a Record Type for Opportunity and delete it later but got an headache finding how to solve this error. Finally, here is the way:

Goto Setup -> Administration Setup -> Manage Users -> Profile

Go inside your corresponding profile and search for that particula Record Type name, in my case it was “Partner Opportunity Record Type”. Edit this and remove not required record types and go back and try to deactivate the record type. Should work now.

Could not load file or assembly ‘MySql.Data, Version=, …” [Solved]

If you are accessing MySql from your ASP.NET code and getting this error after uploading code to Server:

Parser Error Message: Could not load file or assembly ‘MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d’ or one of its dependencies. The system cannot find the file specified.

Make sure /bin/MySql.Data.dll exists on root folder.

I was accessing the code from url

So MySql.Data.dll should be present at location:

Even if you place the .dll in /SomeFolder/bin/, it does not work.

APEX Sharing Violation – Security Review Error Solved

In the process of making a salesforce app live on appexchange, we need to get our package tested and passed from security review team. During such one process, my app got rejected due to APEX Sharing Violation error as reported by Checkmarx Report. It was termed as Apex Force com Serious Security Risk.

Description of Issue:
The platform makes extensive use of data sharing rules. Each object can have unique permissions for which
users and profiles can read, create, edit, and delete. These restrictions are enforced when using all standard
controllers. When using a custom Apex class, the built-in profile permissions and field-level security restrictions are
not respected during execution. The default behavior is that an apex class has the ability to read and update all data
with the organization. Because these rules are not enforced, developers who use Apex must take care that they do
not inadvertently expose sensitive data that would normally be hidden from users by profile-based.

Demonstrative Example:
For example, consider the following Apex pseudo-code:
public class customController {
public void read() {
Contact contact = [Select id from Contact where Name = :value];
In this case, all contact records will be searched, even if the user currently logged in would not normally have
permission to view these records.

The solution is to use the qualifying keywords “with sharing” when declaring the class:
public with sharing class customController {
. . .
The “with sharing” keyword directs the platform to using the security sharing permissions of the user currently logged
in, rather than full access to everything.

More details can be found at

How to work with Excel (.xls) files in C#.NET?

1. Add reference to COM object Microsoft.Office.Excel 12.0 or any other available library.

2. Code:

using Microsoft.Office.Interop.Excel;

private void anyfunction()
   Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();

   Microsoft.Office.Interop.Excel.Workbook xlWkb = null;

   Microsoft.Office.Interop.Excel.Worksheet xlWks = null;

   xlWkb = xlapp.Workbooks.Open(System.Windows.Forms.Application.StartupPath + @”Report.xls”, Missing.Value, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
   xlWks = (Microsoft.Office.Interop.Excel.Worksheet)xlWkb.Worksheets[1];

   //Sample Statement to work on sheets
   xlWks.get_Range(“A2”, “H65000”).ClearContents();

   xlWkb.Close(true, Missing.Value, Missing.Value);

Extracting data from Apple iTunes

I tried a lot to find RSS feeds for latest apps getting posted on Apple iTunes store under all categories but couldnt find anywhere, not sure why Apple does not provide such feed.

So I decided to write one of my own and below is how I accomplished the task using curl in php. Through httpfiddler I first out request headers sent by iTunes software and used the same.



function gunzip($zipped) {
$offset = 0;
if (substr($zipped,0,2) == "x1fx8b")
$offset = 2;
if (substr($zipped,$offset,1) == "x08")  {
# file_put_contents("tmp.gz", substr($zipped, $offset - 2));
return gzinflate(substr($zipped, $offset + 8));
return "Unknown Format";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Apple-Tz: 29600',
'X-Apple-Store-Front: 253477,27',
'Accept-Encoding: gzip',
'Accept-Language: en-us, en;q=0.50',

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo gunzip($output);





How to import Chinese characters in Mysql Table?

I know proper way to do this does exists but I was falling short of time and wasnt able to find perfect solution, so used this a way around to import a list of chinese cities in chinese language to one of my mysql table.

1. 1st changed the table structure to make the city field collation as big5_chinese_ci

2. I had the list of chinese cities in chinese language in excel sheet. Using a small VBA below code, i created mysql insert into query for each of the record:

Sub CreateQueries()
      r1 = 1
      While Range(“A” & r1) <> “”
           Range(“C” & r1) = “insert into cities values(‘” & Range(“A” & r1) & “‘);”

        r1 = r1 + 1
End Sub

3. Then just copy pasted all these generated queries in mysql SQL window and executed the queries and I had proper characters in mysql table 🙂

Initially, I tried to export excel to csv and then importing it in mysql, but it was showing ???? symbols in mysql after import. So this turned out to be cool quick solution. Hope it can help somebody solve similar problem I was facing.


Welcome to Nanostuffs Blog !

This is a portal exclusive for Nanostuffs Brightest Minds to share their technical, personal, and every kind of experience on web. We look forward to keeping you informed with timely articles on wide range of topics, such as:

  • iPhone/iPad Development
  • Android Development
  • Salesforce Customization/Apex Programming
  • PHP Insights
  • .NET Brainstorms
  • Unity 3D Challenges
  • HTML5 Examples
  • ….. and some general ramblings!

Hope you can subscribe to our blog feed, so that you’ll never miss an article. Please feel free to comment. We want to hear from you too.  Is there something specific you’d like for us to blog about?  If so, drop us an email ( and we’ll see what we can do.

Thank you for stopping by and we hope to see you soon.  Stay tuned.  Good things to come.

Nanostuffs Team


You pauperization to let at least 450 writers fix to construe ingress orders Near essays include points that can be supported by facts or by statements within the text that is existence analyzed When he came to see this look of himself, and lettered a figure for it, he did what was already typical of him at that maturity He went to the library

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