views:

331

answers:

2

I am successfully creating a Task using the SalesForce API SOAP API through Java.

However, my problem is that I can't seem to set the Type of it. They all default to "Call" but I really want them to be "Email".

Can someone point me in the direction of where I can do this? I think it is to do with RecordTypeMapping, but i am somewhat confused as to how to use this in my Java code to look up the particular one for Task type.

I feel I have got so close with this. I have the correct WSDL that is giving me the extra method on the Task.java class, but no matter what I pass in, it dies.

This doesn't seem to be a huge ask, yet i am perplexed as to which dots to join to get it to work

Any help would be appreciated. thanks

+1  A: 

(Answer edited, see below)

This field is available through API like any other. Your problem doesn't have anything to do with the RecordTypes either (when you insert a record via API, you can put any String you want as the picklist value).

So let's start with the checklist and if this doesn't help we'll think about more options :)

  1. Is the field visible on the "New Task" page?
  2. What does the "View field accessibility" button say? (put your own org ID in the link, I've used my "na5")
  3. Do you know the Profile of the user whose credentials you use to connect via API (for example "System Administrator")? Can you verify in the "Set Field-Level security" that this Profile can see this field (1st checkbox) and it's not marked as readonly (2nd checkbox)?
  4. Can you try to set up the "Call" as default value for this field and see what happens?
  5. Can you try to insert a new Task through the Salesforce.com Data Loader? If it will work, it will mean that API on it's own is OK (Data Loader also uses the API) and the problem lies somewhere in your app.
  6. If you really need to access the so-called metadata to know what are the possible values of a picklist, you can use the describe() calls. This should get you started but as I said before - as far as I remember the picklist values aren't really enforced when you use API.
  7. Stupid, but... consult your System Administrator if he didn't put any workflows that modify the value of this field. And ask the Apex developers if there are any "before insert" triggers on the Task object...

Edit: Took me longer than expected (Apache Axis 2 generates totally different code to the one I'm used too with Axis 1.x) + I've encountered some other distractions, but I've checked it.

In short: it's a normal field available through API and works for me.

Please make sure that your enterprise WSDL contains lines similar to

<complexType name="Task">
    <complexContent>
        <extension base="ens:sObject">
            <sequence>
                <element name="Account" nillable="true" minOccurs="0" type="ens:Account"/>
                (...)
                <element name="Type" nillable="true" minOccurs="0" type="xsd:string"/>
                (...)
            </sequence>
        </extension>
    </complexContent>
</complexType>

If it does - regenerate your Java classes from it. If it doesn't - download a new WSDL.

With Apache Axis2 and enterprise.wsdl I was able to create such sample code:

Task task = Task.Factory.newInstance();
task.setType("Alan's Email");   // Not a valid picklist value, just to prove that these don't matter when we use API.
task.setWhatId("0067000000AH3ME"); // An Opportunity Id ("Burlington Textiles" in my test org) to which this task will be related.
task.setStatus("Not Started");
task.setPriority("Normal");
task.setDescription("A new Task has been created with methods from Enterprise WSDL.");

You can download the whole test project (rather big) here. There's high chance the code looks weird if you're used to Axis 1.x style (most of the Salesforce API examples are written using old Axis), but I assure you it worked for me.

If you still need help - I guess we'll have to contact directly?

Good luck.

eyescream
This is good information, and thank you for such a detailed response.however, i do not see any corresponding method in my Java stubs (from the WSDL) that would allow me to pass in a Type.
Alan Williamson
You're using "enterprise" WSDL, right? Both this one and "partner" WSDL should offer possibility to do it... Is there a chance that your WSDL was generated before the field became accessible? Or maybe you didn't rerun the Axis code generator? Today evening (I'm in Europe so let's say "in 8-10 hours time") I'll try to play with Java and see for myself, will let you know the results.
eyescream
I have republished the WSDL but there is no method with this method available to me. Its a mystery.
Alan Williamson
Contact me on [email protected] (remove all occurences of "K"), I'll give you access to my developer org and we'll see if the problem lies in your org or maybe somewhere in your process for WSDL generation... At this moment I'm out of ideas what else could be the cause other than too old WSDL or field security settings (mentioned in the checklist) :(
eyescream
eyescream -- you are a genius! That worked.I am sure I had reset all the permissions on the Task object, but must have missed a timing step in producing the WSDL and referencing it.But the setType() function popped up, and i am rocking now.
Alan Williamson
You're welcome :) It's always some stupid overlooked things like that...
eyescream
A: 

The API field name that contains 'Call' (and defaults to it) is a combobox, not a picklist, and it's called Subject.

Task.Subject = 'Email';

If you want to set the default, do it from within the Salesforce app:

Setup->Customize->Activities->Task Fields->Subject

kmb
Both Type and Subject contain by default values "Call", "Email" and "Other". The main difference is that Type is a hidden field out-of-the-box. I don't think Alan wants to specify default, just set the value from Java (i.e. have method like setType/setSubject in code generated from WSDL).
eyescream