Using SalesForce's Web Service to create and s

2019-02-27 18:35发布

问题:

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:

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: for all the users who have problems with Salesforce integration (especially "I've created a new custom field, it seems I can query for it but I don't see it in the returned results") there are couple more steps:

If you're using enterprise WSDL - remember to download fresh copy. Java, C# etc. people need to regenerate their classes from the wsdl ("consume" it again) in order to see new fields. PHP users shouldn't worry (last time I've checked everything is done in runtime in "PHP toolkit"... of course if you've actually generated something out of the WSDL - do it again). But in case of PHP it seems WSDL can be somehow cached in your app. Restart the server to make sure fresh wsdl is used?


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.



回答2:

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