Blog Stats
  • Posts - 19
  • Articles - 1
  • Comments - 21
  • Trackbacks - 0

 

Friday, May 25, 2012

How to Overcome or fix MIXED_DML_OPERATION error in Salesforce APEX without future method ?


How to Overcome or fix MIXED_DML_OPERATION error in Salesforce APEX without future method ?

MIXED_DML_OPERATION :-
one of the worst issues we have ever faced :)

While trying to perform DML operation on a setup object and non-setup object in a single action you will face this error.

Following are the solutions I tried and the final one worked out :-
1. perform the 1st objects DML on normal apex method. Then Call the 2nd objects DML through a future method.
    Drawback :- You cant get a response from the future method as its context is different and because its executing asynchronously and that its static.

2. Tried the following option but it didnt work :-
    1. perform the dml operation on the normal apex method.
    2. tried calling the 2nd dml from trigger thinking that it would be in a different context. But it didnt work.
    
3. Some suggestions were given in some blogs that we could try System.runas()
   Unfortunately that works only for test class.
   
4. Finally achieved it with response synchronously through the following solution :-
    a. Created 2 apex:commandbuttons :-
        1. <apex:commandButton value="Save and Send Activation Email" action="{!CreateContact}"  rerender="junkpanel" oncomplete="callSimulateUserSave()">
            Note :- Oncomplete will not work if you dont have a rerender attribute. So just try refreshing a junk panel.
        2. <apex:commandButton value="SimulateUserSave" id="SimulateUserSave" action="{!SaveUser}"  style="display:none;margin-left:5px;"/>
        Have a junk panel as well just for rerendering  :-
        <apex:outputPanel id="junkpanel"></apex:outputPanel>
    b. Created this javascript function which is called from first button's oncomplete and clicks the second button :-
                function callSimulateUserSave()
                {
                    // Specify the id of the button that needs to be clicked. This id is based on the Apex Component Hierarchy.
                    // You will not get this value if you dont have the id attribute in the button which needs to be clicked from javascript
                    // If you have any doubt in getting this value. Just hover over the button using Chrome developer tools to get the id.
                    // But it will show like theForm:SimulateUserSave but you need to replace the colon with a dot here.
                    // Note :- I have given display:none in the style of the second button to make sure that, it is not visible for the user.
                    var mybtn=document.getElementById('{!$Component.theForm.SimulateUserSave}');                
                    mybtn.click();
                }
    c. Apex Methods CreateContact and SaveUser are the pagereference methods which contains the code to create contact and user respectively.
       After inserting the user inside the second apex method you can just set some public Properties in the page,
       for ex:- created userid to get the user details and display in the page to show the acknowledgement to the users that the User is created.

Wednesday, August 17, 2011

The protocol 'net.msmq' is not supported


The protocol 'net.msmq' is not supported

If you get this error you need to do the following steps :-

You can just do the following if everything is right in place for you :-

1. Open IIS -> Your Website -> Advanced Settings -> Enabled Protocols

       This will have only http. You need to add net.MSMQ separating it by a comma like this : http,net.MSMQ

2. If it still doesnt work you need to do the following for activating MSMQ in your machine :-

  • Open visual studio command prompt as administrator
  • Paste the below line as a single command and press enter

%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.msmq',bindingInformation='localhost']

(Remember: If you have deployed it in a different Site in IIS you need to change the site name in the above command) 

 

If you are still having problems you can follow the steps given in the below URL :-

http://msdn.microsoft.com/en-us/library/ms752246.aspx

Saturday, April 16, 2011

How to Enable USB Port through Regedit in Windows if it is blocked


1. Click Start, and then click Run. 2. In the Open box, type regedit, and then click OK. 3. Locate, and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor 4. In the right pane, double-click "Start". 5. In the Value data box, type "3" (without quotes), click Hexadecimal (if it is not already selected), and then click OK. Note :- if 3 is entered it will open the port and if 4 is entered it will close the port. 6. Quit Registry Editor.

Thursday, December 02, 2010

An Annoying bug in salesforce winter 11 release and how to delete apex classes and triggers in production


There is an annoying bug in salesforce winter 11 release

MyProfilePageController.cls

System.QueryException: List has no rows for assignment to SObject

Class.MyProfilePageController.testSave: line 78, column 35 External entry point

 

This is also the method for deleting Apex Classes and Triggers from Salesforce Production

 

(Note : You cannot delete an apex class or Trigger from Salesforce Production through changesets. Only way is to use Force.com IDE)

 

1. Install and Open Force.com IDE (don't install if you have already done)

2. Create a new Force.com Project connecting to Sandbox (providing the credentials for sandbox including the security token)

3. Delete the MyProfilePage page and the MyProfilePage meta xml under Pages and also delete the MyProfilePageController class and the MyProfilePageController meta xml under classes. (Right click delete). It will ask you whether you need to delete from the sandbox server too. Say No. Click Ok.

4. Right click on Src or the root folder of your project -> Force.com -> Deploy to server

5. Provide production server credentials

6. from the list shown Deselect all

7. Sort by type

8. Navigate to Pages and Check the checkboxes next to MyProfilePage page and the MyProfilePage meta xml (these will be shown in red as you have deleted  it locally )

9. Navigate to classes and Check the checkboxes next to MyProfilePageController class and the MyProfilePageController meta xml (these will be shown in red as you have deleted  it locally )

10. Click Validate and check whether it gives success. (It will.. if u dont have any problems in any other class )

11. Then Click Next. It will delete the salesforce class and page which has the bug and you can proceed with your further deployments. ( In case if it dint succeed, try deleting the above mentioned 4 files (in point no. 3) from the folder where you have mapped the sandbox project and run through all the steps from the point no. 4).

 Here are the supporting links :-

http://sites.force.com/ideaexchange/apex/ideaview?id=08730000000K1QLAA0

http://boards.developerforce.com/t5/Force-com-Sites/Bug-in-SFDC-provided-test-method-for-MyProfilePageController-cls/td-p/209169

 Salesforce is still working on it to fix it from their end during the next release.

 

Wednesday, October 27, 2010

faultcode:'sf:INSUFFICIENT_ACCESS', faultstring:'ClassName: no access allowed to this class.', Salesforce


faultcode:'sf:INSUFFICIENT_ACCESS', faultstring:'ClassName: no access allowed to this class.',  Salesforce

Are you getting the above error in salesforce while the javascript is getting executed ?

the reson is the user doesnt have sufficient access to the Apex class.

Do the following and the issue will get resolved.

Go to Setup->Develop->Apex Classses-> open the Class -> Click Security Button -> Add access to the profile from which you are trying to perform the action.

 

How to overcome - Not able to delete feed tracked changes (Chatter) in Salesforce


I struggled for more than a month to overcome this error

Not able to delete feed tracked changes when the chatter was enabled in Salesforce environment (Sandbox)

and my sandbox size was just 10 MB and it has occupied around 11.3 MB for these feed tracked changes whenever i was

loading account or contact records in the sandbox thru data loader or thru enterprise wsdl.

So i was not able to create even a single record for testing.

Then deleted all accounts and contacts and then tried. Inspite of that it dint work.

At last, I refreshed the sandbox and the issue was resolved.

I got my full 10 MB free space :)

 

Edit Read Only Fields Permission in Salesforce


Learnt a new thing today in Salesforce.

I was wondering how to make a field read only for system admins in Salesforce.

I configured particular fields to read only for a cloned system admin profile :-

  • Field Accessibility
  • Field Level Security
  • Page Layout

In spite of that it was allowing me to edit the field while creating a new record or editing it.

Then found out that if it is a profile that is cloned from System Admin,

We have a Permission called Edit Read Only Fields

and that was checked for that profile.

I disabled the same and saved it and it worked finally.

 

 

Thursday, September 16, 2010

Still not possible to do a Workflow field update for a lookup field (to custom object) in Salesforce


  • Still not possible to do a Workflow field update for a lookup field (to custom object) in Salesforce

Tried doing a field update today for a lookup field for a custom object from a workflow rule.

Unfortunately such an importthat feature is still not implemented

Supporting text from IdeaExchange :

http://ideas.salesforce.com/article/show/10089166

  • 810
    points
    I would like the ability to have a workflow field update,
    update a Lookup (reference) field.
    9 Comments  •  Posted by Matt P  
  • 290
    points
    Today, you cannot use a custom field that is
    type Lookup in a workflow (or Territory Management
    Auto Assignment Rule). Eg: We have a field
    - Distributor - which is a custom lookup field
    to Account. We'd like to use this field in a workflow
    to Update another field on the account, but the field,
    Distributor Name, is not available in the fields to select.
    I put in a case, and was told that Custom Lookup fields
    are not allowed in Workflow or Territory Management
    Auto Assignment Rule - which is really where we wanted
    to use it. Please consider this in the future release.

Tuesday, August 17, 2010

Weird error page "page cannot be displayed" when everything is correct


I was facing a weird error page "page cannot be displayed" when everything is correct

in my asp.net page which is called through ajax from another html page.

But checked the page by copying the url in the browser and pasting it. even then it want working.

Then finally set that aspx page as the startup page and tried executing. it worked then.

Was struggling with this for an hour. What a shame, finally i have found out the reason that there was a space between http: and //

it was like this : http: // instead of http://

Convert DataRowCollection to DataRow[] (Array) in C#


Access the select method of the datatable to convert the DataRowCollection to DataRow[];

You might get an error like this:-

System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level

To overcome that use the select method from the datatable

Ex :-

DataRow[] results = genericDataSet.Tables[0].Select(); 

 

 

Copyright © sathya