0
votes

Hey I am trying to create some object into salesforce. I have: SObject myobj = new SObject(); myobj.setType("MyType"); ...

But I got: exceptionMessage='sObject type 'string' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.'

I didn't just put a 'string' there. Anyone please give some suggestions? Thanks a lot.

2

2 Answers

0
votes

You don't say what you're trying to do by assigning the type, but it looks like you cannot set the type of an sObject in this way. The "string" the error is complaining about is the string "MyType" that you are trying to use to set the type of the sObject.

If you look at the page that describes the methods for sObjects,

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_methods_system_sobject.htm|StartTopic=Content%2Fapex_methods_system_sobject.htm|SkinName=webhelp

you will see that there is no "setType" method, only a "getType" method.

Why do you want to do this ? do you have the type in a variable that you want to use to create an object ?

0
votes

There is a setType() method when using the Partner API. Is this what you are doing?

In this case you just need to follow the exception message. All custom objects have a API name that end with "__c".

Try

myObj.setType("MyType__c");

The error you see can also happen in a completely different way. I found your question while trying to solve my problem with InvalidSObjectFault. In my case, it was not in how I specified the sObject's type. No. It was permissions. One user (Admin) could run the query but another (my API user) couldn't. Turns out the user's profile needs to have permissions set to see the object. If not then you get this fault message!

Posted more about this on my blog:

http://sforcehacks.blogspot.ca/2013/11/invalidsobjectfault-invalidtype.html