0

I've created an Apex Class which inserts new Case. On the tutorial it only returns the ID. I've checked and researched on how to return the CaseNumber value. But it gives me an error on when called on PostMan

APEX Class

    Global static id caseinsert(string Status, string Origin,string SocialMediaAccount, String CustomerID
    ,string Category, string SubCategory, string SConcern,String NatureOfConcern){
   
    Case css = new case(
    Status = Status,
    Origin = Origin,
    Social_Media_Account__c = SocialMediaAccount,
    Billing_Customer_ID__c = CustomerID,
    Case_Category__c =  Category,
    Case_Sub_Category__c = SubCategory,
    Specific_Concern__c= SConcern,
    Nature_Of_Concern__c =  NatureOfConcern

    );
    string casenum;
    insert css;
    css =[select id,CaseNumber from Case where id=:css.id];  
       
    return css.CaseNumber;
    }

Error on Postman

[
    {
        "errorCode": "APEX_ERROR",
        "message": "System.StringException: Invalid id: 00107329\n\nClass.CustomRestAPI.caseinsert: line 30, column 1"
    }
]


2
  • Can you add a debug log after insert case and see if its giving ID properly. and check below things as well - how much row query returns, and if it returns record does casenumber coming. I believe error could be because of 3 reasons - 1. case did not inserted. 2. record did not come back in the querey. 3.(worst case ) the type is not matching - "00107329" it says invalid id for the given case num. so type can also be a issue.
    – Ysr Shk
    Jun 21, 2021 at 3:51
  • (1) and (2) would result in a DmlException and a QueryException respectively. It is a type issue.
    – David Reed
    Jun 21, 2021 at 3:56

1 Answer 1

0

You have declared your method to return an Id:

Global static id caseinsert(...)

but you are returning a value that is not an Id, but a String:

return css.CaseNumber;

Id values are checked for validity on creation. Change your method signature to reflect its actual return value, String.

1
  • Thanks.. found it... Just change Global static id caseinsert(...) to Global static string caseinsert(...) Jun 21, 2021 at 4:14

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.