Creating an Apex REST endpoint to receive updates for Opportunities. The caller of the endpoint will send the full Lightning URL for an Opportunity. For example: https://example.lightning.force.com/lightning/r/0061U00000Gs7RqQAJ/view.
In a report of Opportunities with their Ids, it looks like there are 3 extra chars on the end of the ID in the URL. For example, the above Opportunity has an Id of 0061U00000Gs7Rq rather than 0061U00000Gs7RqQAJ. I need the Id to populate a Lookup(Opportunity) field in an SObject.
Here's the code I'm using to extract the ID from a URL...
private static ID getSalesforceId(String url) {
Pattern urlPattern = Pattern.compile('.*/lightning/r/([a-zA-Z0-9]{15,18})/.*');
Matcher urlMatcher = urlPattern.matcher(url);
ID opportunityId;
if (urlMatcher.matches()) {
opportunityId = (ID) urlMatcher.group(1);
}
return opportunityId;
}
Questions
- Is there an existing method I can call to extract the Id?
- If not, should I clip the last three characters of the Id portion of the URL passed to me or can I use that longer Id to set the value of a Lookup(Opportunity) field?