0

I am able to create custom field on sf object using apex code. But now I want my when a an guest user request with a JSON, I want to create some fields on sf. I am running the same code when request is coming from external system. But I am getting error for the same code which is working in developer console.

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: UNKNOWN_EXCEPTION: Site under construction faultcode=UNKNOWN_EXCEPTION faultactor=

I have modify all checked for the object on which I am trying to create custom field. All the class are added to gust user profile. Do any one have any idea

My site setting enter image description here

  • 2
    You want to alter metadata in org from Guest user context? – Pranay Jaiswal May 3 '18 at 18:23
  • 2
    That seems extremely dangerous. – David Reed May 3 '18 at 18:25
  • yes i want to do same, i.e. i want to create fields on an object using guest user. – Anu May 3 '18 at 18:25
  • If I can create it , I can delete anything, you sure you wanna do this? The guest user is publicly accessible anyone would access and destroy anything. – Pranay Jaiswal May 3 '18 at 18:26
  • 3
    It looks more like xyproblem.info . Can you provide business requirement? I doubt SF will allow guest users to alter metadata. If it does its a security hole in SF architecture which needs to be raised. – Pranay Jaiswal May 3 '18 at 18:28
0

I assume you are making callouts to the Salesforce Metadata API from Apex, possibly using Andrew Fawcett's library to do so. This library grabs the running user's Session ID and includes it in the request. The user in question must have the Modify All Data permission.

Guest Users have no Session ID. Therefore you cannot do this. If you got really creative maybe you might find a way, but still, it is dangerous and highly inadvisable to allow the system to modify its own metadata in response to external requests.

If you need it to be possible to store arbitrary fields sent by an external system, perhaps a better idea is to save a blob of JSON in a Long Text Area or as an attached File. This won't make the data searchable but at least it's stored and "safe" until it can be further processed.

Another possible way to do this could be to have a Master-Detail relationship where the master represents the external record and the detail records represent whatever arbitrary name/value pairs were sent.

| improve this answer | |

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.