2

I am trying to delete an authProvider from APEX.

authProvider provider = [SELECT Id FROM authProvider WHERE DeveloperName = 'a_known_string'];
delete provider;

I get an error that states

DML operation Delete not allowed on AuthProvider

However looking at the object reference, delete() is supported.

Where did I go wrong?

3

Not all objects allow DML in Apex, even if they are allowed in SOAP, REST, etc. I'm not entirely sure why this restriction exists, but when it does, there's not much you can do. In some contexts, you can choose to call a REST API call (e.g. DELETE /services/data/47.9/sobjects/AuthProvider/{recordid}), though it depends on your current context.

HttpRequest req = new HttpRequest();
req.setEndpoint('callout:SFDC/services/data/47.0/sobjects/AuthProvider/'+recordId);
req.setMethod('DELETE');
HttpResponse res = new Http().send(req);
if(res.getStatusCode() == 204) {
    // Success! //

Other methods may also be possible. Just be aware that not all modifiable sObjects can be manipulated directly in Apex.

-1

No we cannot delete the Apex fuction because it is remend to invert what was to what is and what will be as to take and betterment on what seen

  • Welcome to SFSE! Please take the tour and read How to Answer. Right now, this answer is confusing and I'm not sure what it is that you're trying to say. Improving your grammar and punctuation could help here, as could using the formatting options available to you (e.g. "because it reminds us to change what was into what is, and what will be ..." which is better, but I still have no idea what you're trying to say). As always, though, try to spend the time to write a complete answer (what is the problem? how does your approach work?) – Derek F Dec 16 '19 at 15:24

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.