1

I have created custom objects using the Salesforce API's. Is there any way to create a new tab and associate the custom object into it??

Creating Custom Objects using SOAP API

HTTP URL Used: https://<instance_url>/services/Soap/m/25.0

       <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Header>
  <ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">
   <ns1:sessionId>********************</ns1:sessionId>
  </ns1:SessionHeader>
 </soapenv:Header>
 <soapenv:Body>
  <create xmlns="http://soap.sforce.com/2006/04/metadata">
   <metadata xsi:type="ns2:CustomObject" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">
    <fullName>sample__c</fullName>
    <deploymentStatus>Deployed</deploymentStatus>
    <description>created by the Metadata API</description>
    <enableActivities>true</enableActivities>
    <label>sample Object</label>
    <nameField>
     <displayFormat>AN-{0000}</displayFormat>
     <label>sample__c Name</label>
     <type>AutoNumber</type>
    </nameField>
    <pluralLabel>sample Objects</pluralLabel>
    <sharingModel>ReadWrite</sharingModel>
   </metadata>
  </create>
 </soapenv:Body>
</soapenv:Envelope>

Similarily, i have created custom field using the following api:

HTTP URL Used: https://<instance_url>/services/Soap/m/25.0

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Header>
  <ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">
   <ns1:sessionId>*****************</ns1:sessionId>
  </ns1:SessionHeader>
 </soapenv:Header>
 <soapenv:Body>
  <create xmlns="http://soap.sforce.com/2006/04/metadata">
   <metadata xsi:type="ns2:CustomField" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">
    <fullName>sample__c.test__c</fullName>
    <label>test</label>
    <length>100</length>
    <type>Text</type>
   </metadata>
  </create>
 </soapenv:Body>
</soapenv:Envelope>

Now that I have a custom field and a custom object, Is there any way to associate these using http api calls??

  • You can use metadata api – Reshma Jan 16 '17 at 7:28
  • Correct me if i am wrong, metadata api includes adding a dependency jar and calling the function defined in it to work along. Where as rest/soap api are https calls that can be made from my web application using native code without any jar dependency. Is it possible in metadata api to make http requests. P.S: I dont want to include any external jar in my project – Mohan Krishnan Jan 16 '17 at 7:31
  • Can you post what did you try so far – Reshma Jan 16 '17 at 7:37
  • @MohanKrishnan metadata api calls can be made with any client capable of making http requests. You don't necessarily need to use java or a particular jar. – martin Jan 16 '17 at 7:42
  • @martin oh, i wasnt aware of that....will update the question with what all i have done – Mohan Krishnan Jan 16 '17 at 7:43
0

What you have used to create the custom object and custom field in your question was the metadata api. You can tell by the /m/ in the url endpoint. The official documentation for the metadata api can be found here: https://resources.docs.salesforce.com/sfdc/pdf/api_meta.pdf

As for how to create a tab with the metadata api, you should be able to get it to work with the following:

url endpoint:

https://<instance_url>/services/Soap/m/38.0

payload:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Header>
  <ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">
   <ns1:sessionId>*****************</ns1:sessionId>
  </ns1:SessionHeader>
 </soapenv:Header>
 <soapenv:Body>
  <create xmlns="http://soap.sforce.com/2006/04/metadata">
   <metadata xsi:type="ns2:CustomTab" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">
    <fullName>sample__c</fullName>
    <customObject>true</customObject>
    <motif>Custom53: Bell</motif>
    <mobileReady>false</mobileReady>
   </metadata>
  </create>
 </soapenv:Body>
</soapenv:Envelope>
  • Does it take some time, because i could get the success response. But still no tab is showing up with label 'test' tab . I have included <label>test</label> in the payload And by the way, is there any documentation which states on how the payload must be constructed in order to create these tabs, objects?? It would be really useful if i could get a pdf pr docs regarding this! – Mohan Krishnan Jan 16 '17 at 8:17
  • If you get a success response from a metadata api create call, the metadata should be there in your org. Perhaps you're not seeing it because the profile doesn't have permission yet and the tab hasn't been added to the app. @MohanKrishnan – martin Jan 16 '17 at 8:21
  • Thanks martin, it works. But one more issue is that, i could see the custom tab created inside the tabs page. But it isnt showing up in the list from where i can add it to the header (where Leads, Chatter are present). Any suggestions?? – Mohan Krishnan Jan 16 '17 at 9:37
  • @MohanKrishnan I believe that this is a permissions issue. If you go into the profile, there is a tab permission that defaults to Default Off when created through the metadata api. This has to be changed, even for the system admin profile, for it to be visible on the All Tabs page. – martin Jan 16 '17 at 9:39
  • Yup, i have to change the tab visibility settings to make it visible. One last question, Is there any way to change/override this visibility setttings. – Mohan Krishnan Jan 16 '17 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.