Osama's Weblog

The place where you get updated!
  • rss
  • Home
  • Who am I?
  • RSS Feeds

“Mixed DML Operation” Exception

Osama | August 21, 2010

I am writing after quite a long time. Was busy at work and studies as well.

There is a very annoying exception “MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): {sObject} original object: {sObject}”

There you cannot perform DML on what salesforce calls setup objects(User in this case) and non-setup object in the same context.

There is a workaround that allows multiple DML operations in same transactions

If you want to perform two DML operations sequentially, create a separate method for 2nd DML operation with @future token.
make sure you put System.RunAs() in the method. Your overall method should look like this

private static void myFunc()
{
///1st DML operation
User usr = [Select id from User where Id = :UserInfo.getUserId()];
System.RunAs(usr)
{
Test.startTest();
myFunc2();
Test.stopTest();
}
}@future
private static void myFunc2()
{
///2nd DML operation
}

I hope this helps

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, General, salesforce
Comments rss Comments rss
Trackback Trackback

Paypal X toolkit for Force.com

Osama | July 19, 2010

Last month Salesforce.com and PayPal announced Paypal X toolkit for Force.com Platform.

PayPal, as everybody knows is the most commonly used payment gateway in e-commerce world. The important points about PayPal are:

  • Facilitates payments
  • Pay anyone, receive from anyone
  • Account management
  • Tools for information and reporting

PayPal provides its APIs for integration with other e-commerce websites. They recently launched few changes in their system which are :

  • Pre-approval APIs
  • Refund
  • Convert Currency
  • Parallel Payments
  • Chained Payments

Using Parallel payments, you can split a single payment to any number of receivers. For example, a person purchases different items from different sellers. The person doesn’t have to arrange separate transactions for each seller. What he can do is just arrange a single payment which can be distributed among all the sellers. Isn’t it great?

Using Chained payments, you can send one payment to specific merchant who can further sends the payment after keeping his share. For example, you buy a product through a sales rep of an organization. You can arrange a chained payment for this purpose. You will pay to the sales rep and which will be forwarded to the organization’s account after the share of sales rep is deducted.

Force.com PayPal X toolkit is a set of apex classes for accessing API more easily. You can access them through force.com IDE after installing them into your organization. It takes care of transport . It securely manages API credentials. There is a custom object where you store your API credentials. It also supports adaptive accounts. It is easy to access PayPal sandobx sandbox, beta and live environments.
To access it, sign up on X.com. Obtain application ID from MyApps page. Now, create PayPal sandbox test account and signup on  http://developer.paypal.com. Now, Create test accounts for sandbox and obtain API credentials.

Install PayPal X toolkit from code share.

There are sample codes available for every kind of request that PayPal supports.
Now you don’t have to waste your time in writing custom code to integrate PayPal into your system. Just modify the template classes in the toolkit (which is usually the change in API credentials and some other information as required).

More info on this can be found at webinar by salesforce.com.

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, General, salesforce
Tags
force.com, paypal, PayPal X, salesforce
Comments rss Comments rss
Trackback Trackback

Visualforce enhancements

Osama | June 26, 2010

I was studying the latest pages developers guide and found some components that have been added to salesforce.com.

These are

  • Apex Panel Bar
  • Apex Panel Grid
  • Apex Tab Panel

These controls can further enrich the user experience and the developer can now avoid to use external library components such as jQuery etc in visualforce.

I have created a simple demo which can show these working. Its almost same as in the guide.

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, VisualForce, salesforce
Tags
APEX, paelbar, panelgrid, salesforce, tabpanel, VisualForce
Comments rss Comments rss
Trackback Trackback

Enforcing 1:1 relationship in Salesforce.com

Osama | June 3, 2010

I was wondering what if I have to create a one to one relationship between two objects. There is no declarative way where we can specify a one to one relationship between two objects.

We can write a trigger to enforce a one to one relationship between two objects. The trigger can be written on the child object that validates if there is any other record with same Parent record ID. If found then instead of inserting the record, it gives an alert.

The trigger will generate a list of child objects with specified parent ID. If the list’s length that is retrieved is greater than one, it will generate an alert.

List<ChildObject> co = [select name from ChildObject where parentId = ParentId]
If  (co.Size() < 2)
{
//insert
}
else
//generate alert

  • Share/Bookmark
Comments
3 Comments »
Categories
APEX, salesforce
Tags
APEX, salesforce, trigger
Comments rss Comments rss
Trackback Trackback

How to: Retrieve a list of sObjects in Apex

Osama | May 11, 2010

Some one asked me how to retrieve a list of sObjects in an SF organization using Apex and bind it to a picklist in a VisualForce page.

List of sObjects is returned when you hit the schema of your SF organization. You can get the Label of sObjects as well as API names.

The following code snippet shows how to do the above mentioned task

VisualForce page:

<apex:page controller="Schema2" >
<apex:form >
<apex:SelectList value="{!val}" size="1">
<apex:selectOptions value="{!Name}"></apex:selectOptions>
</apex:SelectList>
</apex:form>
</apex:page>

Apex Controller Code:

public class Schema2 {
public String val {get;set;}
public List<SelectOption> getName()
{
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values(); //extracts the List of sObjects in an organization
List<SelectOption> options = new List<SelectOption>();
for(Schema.SObjectType f : gd)
{
options.add(new SelectOption(f.getDescribe().getLabel(), f.getDescribe().getLabel()));
}
return options;
}
}

Feel free to ask any questions

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, General, salesforce
Tags
APEX, salesforce, sObjects
Comments rss Comments rss
Trackback Trackback

Apex InputField on Force.com site (contd..)

Osama | March 10, 2010

Few days ago I wrote a blog post in which I mentioned that I wasn’t able to access apex:input field on a force.com site. With the help of a my blog reader, I figured out what was the problem. Its pretty straight forward.

You cannot give extra permissions to standard objects on a force.com site. But  you can give Modify All Data and View All Data permissions to a custom object . That means you can use apex:inputField on a force.com site which is bound to a custom object field. Make sure about field level security.

Thanks to Jason.

  • Share/Bookmark
Comments
2 Comments »
Categories
APEX, VisualForce, salesforce
Tags
APEX, force.com, inputField
Comments rss Comments rss
Trackback Trackback

JQueryUI Datepicker in a Visualforce page

Osama | March 4, 2010

JQuery has always fascinates me. It makes the UI very attractive and user friendly. I had to implement a datepicker in a text field. I decided to use the JQuery UI datepicker. I am sharing the code that I did. Its easy to understand.

I made a static resource with the name slider and uploaded all the css and js files of JQuery UI that are available for download here .

1) Include the css files in your page

<link type="text/css" href="{!URLFOR($Resource.Slider, 'themes/ui-lightness/ui.all.css')}" rel="stylesheet" />
<script type="text/javascript" src="{!URLFOR($Resource.Slider, 'jquery-1.3.2.js')}"></script>
 <script type="text/javascript" src="{!URLFOR($Resource.Slider, 'ui/ui.core.js')}"></script>
 <script type="text/javascript" src="{!URLFOR($Resource.Slider, 'ui/ui.datepicker.js')}"></script>

2) Make a input text field and create the following JQuery function as below

 <input id="datepicker" type="textbox" />
<script type="text/javascript">
    $(function() {
        $("#datepicker").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: '{!$Resource.calendar}' });
    });
    </script>;;

3)   $(“#datepicker”).datepicker({ showOn: ‘button’, buttonImageOnly: true, buttonImage: ‘{!$Resource.calendar}’ });
The datepicker pops up when you click on the image button that is created using the above statement. If  you want to pop it up by clicking the textbox only, replace the above statement with the below one:

  $(“#datepicker”).datepicker();

I hope it helps for you as it did for me. Feel free to ask questions

  • Share/Bookmark
Comments
11 Comments »
Categories
APEX, General, VisualForce, salesforce
Tags
APEX, datepicker, jquery, VisualForce
Comments rss Comments rss
Trackback Trackback

Apex InputField on Force.com Site

Osama | February 17, 2010

I came across a strange situation today when I was trying to use a apex:inputField tag and call it on a visualforce page through force.com site. But the field wasn’t visible when seen on public force.com site.

This is what I did

 public class testClass
          {
               public Account acc {get; set;}
          }

and here is the visualforce page

<apex:page   controller=”testClass”>
<apex:inputfield value=”{!acc.Name}”/>
</apex:page>

I also changed the permissions in Force.com guest user profile. But still I wasn’t able to make the field visible. I think its a limitation from security point of view.

If someone else has experienced the same thing or has any recommendations, do let me know.

  • Share/Bookmark
Comments
1 Comment »
Categories
APEX, VisualForce, salesforce
Tags
APEX, force.com, inputField
Comments rss Comments rss
Trackback Trackback

Placing a visualforce page on sidebar

Osama | January 26, 2010

Placing a visualforce page on sidebar is really simple.

1) Create a visualforce page.

2) Create a custom  HTML homepage component. Place the following code in the HTML area.

<iframe src="/apex/[PAGE NAME]?core.apexpages.devmode.url=1" width="100%" frameborder="0" height="100"></iframe>

replace [PAGE NAME] your custom page name.

3)Place it on the left side of home page layout.

and here u go…

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, VisualForce, salesforce
Tags
salesforce, sidebar, VisualForce
Comments rss Comments rss
Trackback Trackback

“An error occurred on your page” issue

Osama | January 22, 2010

I was deploying an apex class through Force.com IDE on a production environment. It was continuously giving me an error “An error occurred on your page”. I wasnt getting the message but on some googling I came to know that my class was using many pageReference methods which were returning some page. The problem was pages include the class as their controller and the in the class pages were being called. The deployment method is sequential on force.com IDE which was creating problem.

The pages were not deployed on the production environment and that is why it was giving me the error. I found a solution somehow. What I did was, removed the ‘return page.myPage’ from the class and include ‘return null’. The class was deployed. Then I deployed the pages. After the pages got deployed, I edited the class, replaced the ‘return null’ statement wirh “return page.MyPage”. This requires lot of rework but solved my problem.

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, General, VisualForce, salesforce
Tags
An error occurred on your page, force.com, IDE
Comments rss Comments rss
Trackback Trackback

« Previous Entries

My status

Categories

  • .NET
  • APEX
  • consulting
  • General
  • Oracle CRM on Demand
  • salesforce
  • Uncategorized
  • VisualForce

MM Did You Know?

A duck`s quack doesn`t echo. No one knows why.
Plugin by mmilan

Its all about cloud

Salesforce

.NET .NET 4.0 beta actionFunction actionSupport administrator android APEX Apex variable API button certification cloud computing consulting controller custom DoDirectPayment force.com GET goggles google html images input inputField JavaScript jquery master-detail matcher Parallel Programming parameters pattern paypal query string REGEX regular expression salesforce search url variable Visual Force VisualForce Visual Studio vmware web service XML PARSING DOM SAX STAX

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

My Tweets

Error: Please make sure the Twitter account is public.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox