function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pooja GargPooja Garg 

How to use Tooling API to create dynamic Triggers in Apex code


   I have a requirement of creating dynamic triggers for Custom Objects which are also being created dynamicaly through MetaData API . 


I search and came to know that Tooling API can help me creating dynamic triggers for REST API but  I am not getting how to configure this to my project and use it.....................



Can I get some example of creating dynamic Triggers through Tooling API..........................


Well I tried 


String json = '{"Name" : "COTrigger", \'"TableEnumOrId" : "Inventory__c"\',\'"Body" : "trigger COTrigger on Inventory__c (after insert) { }"\'}'; 

LoginResult loginResult = binding.login('', 'Test1234@');

        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization','OAuth 00D90000000nlxu!AQIAQCuO8z08yJ1hMR_4.OEL_RYoBwKaWMK4ttOpLevsJBRqFIptV2lkenMZIXObFS3n3EtJmNBjjyWGF8ZM7xp_DX9IEHNw');

        Http httpReq = new Http();
        HttpResponse res = httpReq.send(req); 

 which always give me error as "16:24:52:435 USER_DEBUG [16]|DEBUG|hii[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]"


Although I checked and copy pasted Session ID correctly still it gives me this error again n again.... 


Any kind of help would be appreciated.


Thanks in advance...!!!



its authentication issue,you need to change parameter oauth .Its issue with your parameter.there is some other parameter while connecting with rest.