Talent-Catalog / talentcatalog

https://tctalent.org
GNU Affero General Public License v3.0
12 stars 4 forks source link

Error 400 Bad Request from Salesforce API and Missing Create Job Button #1045

Closed EhsanEhrari closed 1 month ago

EhsanEhrari commented 4 months ago

While attempting to add a Salesforce link to create a new job, I encountered the following error:

org.springframework.web.reactive.function.client.WebClientResponseException$BadRequest: 400 Bad Request from POST https://test.salesforce.com/services/oauth2/token?grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiAiM01WRzlpQmFIUVJmcmVCbXpWaGVqWU5WNWpyVVBCSmJPLmJvaVVHTTN0aFF5am5MWVJOY25VaTZhUWdfaXNzMkhvMUZ0djg5c04ycWJydV9neHJVNiIsICJzdWIiOiAic3NjaGxpY2h0QHRhbGVudGJleW9uZGJvdW5kYXJpZXMub3JnLnNmc3RhZ2luZyIsICJhdWQiOiAiaHR0cHM6Ly90ZXN0LnNhbGVzZm9yY2UuY29tLyIsICJleHAiOiAiMTcxNjkwMjY4NiJ9.Y1AdUGYZgj9B8_TlfSP5bYRVXwBQbsN80-PPwJV_KQa296pvbKnDwjXvyqWXPyHiY_GL6hR3HdE1Cs6mhQVva5EA2vd9Sw1kIhLTQItXy1HnyfqauMWCHUSyI2XS4TQ0oaWHIUzvVsyEwsZmWtf7QC7p793fgnacyg9DH9OO9o4

Additionally, the "Create Job" button is not appearing for creating new jobs.

Steps to Reproduce:

  1. Attempt to add this Salesforce link for creating a new job.
  2. Observe the 400 Bad Request error from the Salesforce API.
  3. Note that the "Create Job" button is not visible in the interface.

This issue blocks the creation of new jobs, impacting the workflow significantly.

samschlicht commented 4 months ago

@EhsanEhrari I picked this one up this morning, since it's a blocker.

Looking at your error more closely, it's an issue with your Salesforce authorisation. I think you will see the same error when attempting to use other Salesforce-linked functionality. Have you started using the new tc_secrets.txt, which was first shared on 20 May (link)?

I am finding that the SF link you've shared is working and the 'Create job' appearing, so as a first step perhaps you could check your environment variables are set up and let me know if you're still facing the same issue? Here's the relevant section of the TC readme. Feel free to give me a call if you think a chat would be useful!

EhsanEhrari commented 4 months ago

@samschlicht It fixed by re-running all python scripts, re-running server and back-end portal. Regarding the tc_serets.txt I was using the new one since you message them on slack.

samschlicht commented 4 months ago

@EhsanEhrari so are you still getting the Salesforce 400 error when you enter this link? Because I'm able to add it without issue. If you are, perhaps we can take 5 mins together to take a look?

EhsanEhrari commented 4 months ago

When adding the link no button is showing for me and there is also no error. I tried the new way of creating job, by adding Employer Partner checked to partner and when going to new job page I can see the create job button, When adding for example 'Software Engineer' and click on create job button, I am getting the below error: 400 Bad Request from PATCH https://talentbeyondboundaries--sfstaging.sandbox.my.salesforce.com/services/data/v58.0/sobjects/Opportunity/TCid__c/36: [{"message":"Value does not exist or does not match filter criteria.","errorCode":"FIELD_FILTER_VALIDATION_EXCEPTION","fields":["Recruiter_Partner__c"]}]

EhsanEhrari commented 4 months ago

We can have a 5 min call if you want

samschlicht commented 4 months ago

Ehsan and I also discussed some issues with job creation without an SF link, but I believe those are moving ahead in Caroline's issue. I'm purely going to address the sf link bug, which is two-fold:

  1. Firstly, the 'Create Job' button and it's menu are not appearing when certain links are entered
  2. This error is appearing during job creation: Screenshot 2024-06-03 at 10.15.12 AM.png
samschlicht commented 4 months ago

The first part is not a TC bug but something for users to be aware of when creating a job from an SF link (and perhaps we should have an instructive error message).

When you right-click on a link to a job opp in Salesforce and select 'Copy link address' or similar, it provides a link that doesn't contain text identifying the record type (e.g. Account, Opportunity), e.g.: https://talentbeyondboundaries--sfstaging.sandbox.lightning.force.com/lightning/r/006Uu000001vzxUIAQ/view

User needs to click on the link and then copy the URL from the address bar:

Screenshot 2024-06-03 at 10.21.30 AM.png

That's on account of the method used by the server to identify the SF record type:

Screenshot 2024-06-03 at 10.22.36 AM.png

At present, our front-end validator patterns allow a shortened version of the URL that works in SF Lightning but not the API.

samschlicht commented 4 months ago

Okay, the second part is just an issue with our dev setup:

During TC job creation, SF receives the API call to update the job opportunity — it will return an error when it finds that another job opp has the same value for TCid (one of the rules on that field is that it has to be unique).

As developers we all have our own local DB, but we're using the same SF sandbox. On our TC DB, SalesforceJobOpp IDs are increasing sequentially, so it's easy to see how any of us could end up submitting a duplicate, given we're all starting off with the same DB dump.

By way of illustration, I'll replicate this error on purpose...

  1. The next salesforce_job_opp created in my DB will be given the ID 38:

    Screenshot 2024-06-03 at 11.40.25 AM.png
  2. I'll edit an existing opp and give it the value 38 for TCid:

    Screenshot 2024-06-03 at 11.42.44 AM.png
  3. Now when creating a new TC job opp from a fresh link, I get the same error!

    Screenshot 2024-06-03 at 11.44.07 AM.png

This error will obviously not happen in production since there's only one TC DB.

My suggested workaround for working in dev is to check which ID your next job will be given, then create a list view in the SF Opportunities tab, filter for an opp that already has it, and delete it! It's not perfect (we will step on one another's toes from time to time by deleting a SF opp that someone is working with), but I think problems will be rare enough that this is the most sensible solution for now — especially given we soon won't be working with SF links but instead creating jobs from scratch.

Screenshot 2024-06-03 at 11.46.36 AM.png
samschlicht commented 4 months ago

So, after investigation, I think the only action items from this bug are to