{"id":7253,"date":"2023-03-28T11:49:28","date_gmt":"2023-03-28T11:49:28","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=7253"},"modified":"2023-04-11T10:58:54","modified_gmt":"2023-04-11T10:58:54","slug":"how-to-create-custom-field-in-salesforce-using-postman-rest-api","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/03\/28\/how-to-create-custom-field-in-salesforce-using-postman-rest-api\/","title":{"rendered":"How to Create Custom field in Salesforce using postman REST API"},"content":{"rendered":"\n<p>In this blog will show you how to <strong>How to Create Custom field <\/strong>in Salesforce using postman REST API. For this blog we take Opportunity object as reference.<\/p>\n\n\n\n<p>Firstly, you have to create <a href=\"https:\/\/help.salesforce.com\/s\/articleView?id=sf.connected_app_create_basics.htm&amp;type=5\" target=\"_blank\" rel=\"noreferrer noopener\">connected app<\/a> in Salesforce.<\/p>\n\n\n\n<p>Now let&#8217;s See <strong>How to Create Custom field in Salesforce using postman REST API. <\/strong>Before start take note of your <strong>Consumer Key <\/strong>and <strong>Consumer Secret <\/strong>present in the <strong>API (Enable OAuth Settings) <\/strong>as these would be required for authentication. The <strong>Consumer Key <\/strong>is visible directly but to get the consumer secret, click on the <strong>Click to Reveal <\/strong>link to see it. It<strong> will use to get <\/strong><a href=\"https:\/\/help.salesforce.com\/s\/articleView?id=sf.remoteaccess_oidc_initial_access_token.htm&amp;type=5\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Access token<\/strong><\/a><strong> from your Salesforce org.<\/strong><\/p>\n\n\n\n<p>We have to connect our Salesforce org with Postman follow the below steps:-<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open Postman and set Authorization type to <strong>OAuth 2.0<\/strong>.<\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/1.Authorization-Type.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/1.Authorization-Type.png\" alt=\"Authorization Type\"><\/a><\/center>\n<font size=\"2\"><center><i>Authorization Type <\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\"><li>Select Token as <strong>Available Token <\/strong>give a name to the token and Header Prefix remain as it is default.<\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/2.Set-Token-Name.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/2.Set-Token-Name.png\" alt=\"Set Token Name\"><\/a><\/center>\n<font size=\"2\"><center><i>Set Token Name <\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Now we have to Configure a new token for Connection purpose. Go to <strong>Configure a new token<\/strong> Section click on <strong>Configuration Options <\/strong>then Enter a token Name, Select Grant Type as Authorization Code, For callback URL Enter URL which is added in Callback URL field while creating Connected app<\/li><li>For Auth URL field If the org is production then &#8220;https:\/\/login.salesforce.com\/services\/oauth2\/authorize&#8221; or for Test Org &#8220;https:\/\/test.salesforce.com\/services\/oauth2\/authorize&#8221;<\/li><li>For Access Token URL field If the org is production then &#8220;https:\/\/login.salesforce.com\/services\/oauth2\/token&#8221; or for Test Org <\/li><li>In Client Id field enter <strong>Consumer Key and in Client Secret enter Consumer Secret. After that leave remaining as it is.<\/strong><\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/3.Configration-Options.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/3.Configration-Options.png\" alt=\"Configration Options\"><\/a><\/center>\n<font size=\"2\"><center><i>Configration Options<\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\"><li>Click on Get New Access Token Button on the bottom side of the Configuration Options Section. After that new prompt will open. In that prompt enter login user credentials and hit login. After that you got prompt on postman says Authentication Completed then hit on proceed.<\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/4.Authorization-Success.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/4.Authorization-Success.png\" alt=\"Authorization Success\"><\/a><\/center>\n<font size=\"2\"><center><i>Authorization Success <\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\"><li>Then another prompt appear where you can see your Access token. Then click on Use Token button. Now you successfully Connected your Salesforce org<\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/5.Access-Token.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/5.Access-Token.png\" alt=\"Access Token\"><\/a><\/center>\n<font size=\"2\"><center><i>Access Token <\/i><\/center><\/font>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><em><span style=\"text-decoration: underline;\">Let&#8217;s Create Custom field for Opportunity object<\/span><\/em><\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Firstly we have to Create New <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_classes_annotation_rest_resource.htm\" target=\"_blank\" rel=\"noreferrer noopener\">RestResource Annotation<\/a> enabled Apex Class in Salesforce Org. Please Referred below apex class<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestResource(urlMapping = '\/Customfields')\nglobal class CreateCustomfields \n{\n    @HttpPost\n    global static Map&lt;String,String&gt; GenerateCustomfields(String fieldType,String ObjectName,boolean Required,integer length,String label,String description,String inlineHelpText) \n    {\n  Map&lt;String,String&gt; Resp = new Map&lt;String,String&gt; ();\n  HttpRequest request = new HttpRequest();\n  request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());\n        request.setHeader('Content-Type','application\/json');\n        request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'\/services\/data\/v56.0\/tooling\/sobjects\/CustomField\/');\n  request.setMethod('POST');\n        if(fieldType == 'Text')\n        {\n            request.setBody('{\"Metadata\" : {\"type\" : \"'+fieldType+'\",\"description\" : \"'+description+'\", \"inlineHelpText\" : \"'+inlineHelpText+'\",\"label\" : \"'+label+'\",\"length\" : '+length+',\"required\" : '+Required+'}, \"FullName\" : \"'+ObjectName+'.'+label.replace(' ','_')+'__c\"}');\n        }\n        else\n        {\n            Resp.put('Error','Please provide field type');\n            return Resp;\n        }\n        Http http = new Http();\n        HTTPResponse res = http.send(request);\t\n        if(res.getStatusCode()==200 || res.getStatusCode()==201)\n        {\nResp.put('Success','status: '+res.getStatus()+' Status Code: '+res.getStatusCode());\nResp.put('StatusCode',''+res.getStatusCode());\nMap&lt;String, Object&gt; m = (Map&lt;String, Object&gt;) JSON.deserializeUntyped(res.getBody());\n            Resp.put('requestgetBody',URL.getSalesforceBaseUrl().toExternalForm()+'\/lightning\/setup\/ObjectManager\/'+ObjectName+'\/FieldsAndRelationships\/'+''+m.get('id')+'\/view');\n        }else\n        {  String body=res.getBody();\n            Resp.put('Error',''+res.getStatus());\n            Resp.put('StatusCode',''+res.getStatusCode());\n            body=body.substring( 1, body.length() - 1 );\n            map&lt;String,object&gt; m = (map&lt;String,object&gt;) JSON.deserializeUntyped(body);\n            Resp.put('ErrorMessage',''+m.get('message'));\n            Resp.put('Endpoint',''+request.getEndpoint());\n        }\n        return Resp;\n    }\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li><strong>Enter your Salesforce URL + \/services\/apexrest\/Customfields in URL Section and Select method type as POST<\/strong><\/li><li><strong>Now click on Body section select format as raw type as a JSON and enter following scrip in below section<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"fieldType\" : \"Text\",\n    \"ObjectName\" : \"Opportunity\",\n    \"Required\" : false,\n    \"length\": 255,\n    \"label\" : \"Comment\",\n    \"description\" : \"Comment\",\n    \"inlineHelpText\" : \"Opportunity Comment\"\n}<\/code><\/pre>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/6.Enter-Body.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/6.Enter-Body.png\" alt=\"Create Custom Field\"><\/a><\/center>\n<font size=\"2\"><center><i>Enter Body <\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In above script those are the parameters of the Above Apex class (field Type refers to type of Custom field, ObjectName refers to in which object field should be created, Required refers to field Should be required or not, Label is Custom field Label ,description is Custom field Description, inlineHelpText is Custom field help text).<\/li><li>After that click Send button. Now you can see response contains of Custom field URL to verify Field as well as Status code and Success method<\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/7.Custom-field-Created.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/7.Custom-field-Created.png\" alt=\"Custom field Created\"><\/a><\/center>\n<font size=\"2\"><center><i>Custom field Created <\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\"><li>Now you can see Custom field has been successfully created in your Salesforce org.<\/li><\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/8.Custom-field-Created-in-Salesforce.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/03\/8.Custom-field-Created-in-Salesforce.png\" alt=\"Custom field Created in Salesforce\"><\/a><\/center>\n<font size=\"2\"><center><i>Custom field Created in Salesforce <\/i><\/center><\/font>\n\n\n\n<p>By following the above blog instructions, you will be able to \u201c<strong>How to Create Custom field in Salesforce using postman REST API<\/strong>\u201c. If you still have queries or any related problems, don\u2019t hesitate to contact us at <a href=\"mailto:salesforce@greytrix.com\" target=\"_blank\" rel=\"noreferrer noopener\">salesforce@greytrix.com<\/a>. More details about the Product are available on <a href=\"https:\/\/www.greytrix.com\/product\/gumu\/salesforce-sage-erp-integration\" target=\"_blank\" rel=\"noreferrer noopener\">our website<\/a> and <a href=\"https:\/\/appexchange.salesforce.com\/listingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noreferrer noopener\">Salesforce AppExchange<\/a>.<\/p>\n\n\n\n<p>We hope you may find this blog resourceful and helpful. However, if you still have concerns and need more help, please get in touch with us at <a href=\"mailto:salesforce@greytrix.com\" target=\"_blank\" rel=\"noreferrer noopener\">salesforce@greytrix.com<\/a>.<\/p>\n\n\n\n<p style=\"text-align: justify\"><b>About Us<\/b><\/br>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> \u2013 a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.<br><br> Greytrix has some unique solutions for Cloud CRM such as <a href=\"\">Salesforce Sage integration<\/a> for <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/integration\/\">Sage X3<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-100-integration\/\">Sage 100<\/a> and <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-300-integration\/\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/data-migration-support\/\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Integrated App development<\/a>, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star rated app listed on <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<br> The GUMU&#x2122; Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.<br><br> For more information on our Salesforce products and services, contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n\n\n\n<p><strong>Related Posts: <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/01\/18\/how-to-get-list-of-apex-class-by-using-apextypeimplementor\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Get List of Apex Class by using ApextypeImplementor<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/01\/18\/how-to-get-list-of-apex-class-by-using-apextypeimplementor\/\" target=\"_blank\" rel=\"noreferrer noopener\">Use Of Fault Connector in Flow Builder<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/01\/18\/how-to-get-list-of-apex-class-by-using-apextypeimplementor\/\" target=\"_blank\" rel=\"noreferrer noopener\">Navigation Service in LWC<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/01\/18\/how-to-get-list-of-apex-class-by-using-apextypeimplementor\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Use Static Resources In LWC<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this blog will show you how to How to Create Custom field in Salesforce using postman REST API. For this blog we take Opportunity object as reference. Firstly, you have to create connected app in Salesforce. Now let&#8217;s See How to Create Custom field in Salesforce using postman REST API. Before start take note\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/03\/28\/how-to-create-custom-field-in-salesforce-using-postman-rest-api\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1415,1408,1413,67,68,610,70,1414,1409,1407,1411,367,1410,1412],"class_list":["post-7253","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-api-to-create","tag-connect-salesforce-with-postman","tag-custom-field-creation","tag-custom-fields","tag-custom-object","tag-custom-object-in-salesforce","tag-custom-settings","tag-customfield-tooling-api","tag-postman-rest-api","tag-rest-api","tag-restresource-annotation","tag-salesforce","tag-salesforce-rest-api","tag-tooling-api"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=7253"}],"version-history":[{"count":5,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7253\/revisions"}],"predecessor-version":[{"id":7319,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7253\/revisions\/7319"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=7253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=7253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=7253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}