0

I am trying to insert record into Member Plan object using composite API. Note : For simplicity in the below request I removed all other post in coposite API and adding only one with hard coded values

string bodyVal='{ "compositeRequest": [  { "method": "POST", "url": "/services/data/v45.0/sobjects/MemberPlan", "referenceId": "refMemberPlan", "body": {"MemberId": "0018b00002Q5fL0AAJ", "PayerId": "0018b00002LHZUYAA5", "MemberNumber": "36478019000",  "Name" : "LIBERTY NETWORK" } }] }';

                req.setHeader('Authorization','Bearer '+getAccessToken.Access_Token__c);
                req.setHeader('Content-Type', 'application/json'); 
         
                req.setEndpoint(envDetails.Base_URL__c+ '/services/data/v55.0/composite/'); 
                req.setMethod('POST'); 
                req.setTimeout(120000);
                req.setBody(bodyval); 
                Http h = new Http(); 
                HttpResponse res = h.send(req); 

but getting this error

{"compositeResponse":[{"body":[{"message":"entity type cannot be inserted: Member Plan","errorCode":"CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY","fields":[]}],"httpHeaders":{},"httpStatusCode":400,"referenceId":"refMemberPlan"}]}

I tried by inserting into direct object as like below

MemberPlan plan= new MemberPlan();
plan.MemberId='0018b00002Q5fL0AAJ';
plan.PayerId='0018b00002LHZUYAA5';
plan.MemberNumber='36478019000';
Plan.Name='LIBERTY NETWORK';
insert plan;

and it is going through.

I havent didn't do any code change and suddenly getting this issue in PROD but things are working fine in sand box

3
  • 1
    Try keeping you API version in sync. Anyways that shouldn't affect this call. I dont see any issue on your code. Check the user permission. The integration user who is making the composite api call. Commented Apr 17, 2023 at 6:06
  • @NagendraSingh .As like you said its permission issue
    – SFDC buddy
    Commented Apr 19, 2023 at 22:32
  • In that case, I will post this as an answer below. Commented Apr 20, 2023 at 3:23

1 Answer 1

0

When using rest api to insert object. The running user needs to have access to do that operation.

It works in apex because apex runs in System mode.

Please check the permissions assigned to user with which the API call is being made.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .