Activity Forums Salesforce® Discussions How to get Custom field id in Salesforce? Reply To: How to get Custom field id in Salesforce?

  • Sourabh

    Member
    September 15, 2016 at 12:30 pm

    Hi Tanu,

    To get custom field Id in Salesforce you have to use Tooling Api. Here is a piece of code , Hopefully it will help you.

    HttpRequest req = new HttpRequest();
    req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
    req.setHeader('Content-Type', 'application/json');

    String toolingendpoint = 'https://na1.salesforce.com/services/data/v20.0/tooling/';

    //query for custom fields
    endpoint += 'query/?q=select+id,DeveloperName,FullName+from+CustomField+limit+1'
    req.setEndpoint(endpoint);
    req.setMethod('GET')

    Http h = new Http();
    HttpResponse res = h.send(req);
    system.debug(res.getBody());

    Thanks