Monday, November 28, 2011

Exception : Can't use Setup and Non-Setup DML Operation in same Context

Topic In Detail: We face this situation sometime when we want to use DML opertaion in SetUp Object(like user) and Contact (like Contact or any custom Object) as well. but that we got this error.

Solution:

Use Future class to resolve this Exception.

What is Future Class:

This is a class with added syntax(@future) like we do in testclass (@isTest), and in this future class u can use DML exception on any one of them.

So it will add the DML in your batch process / process heap and will execute this DML after some time.

so this way u can change the context of both of them and resolve this issue.

For more guidance, reach me at:
http://www.amitgoyal09.blogspot.com
http://www.salesoncloud.blogspot.com
nicsplacement@gmail.com
linkedIn, Twitter, IM by name amitgoyal09

Thanks,
Amit Goyal
Online Trainer and SalesForce Developer
(SalesForce, MCA, BCA,RHCE)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.