function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pedro Garcia GPedro Garcia G 

trigger show error & @future

Hi...

I have a task but I don't know how to afford it. I appreciate any help.
Application:
The app must connect to a third API through RESTFull and pull data.
The first step: the user enters the API KEY in the config page.
Task Requirement:
The API KEY must be entered in the config page. Once the user enters the API KEY the record must be created only if the API KEY is good. It means only if the connection succeeded.

My issue:
I create a Trigger in the CONFIG__c object with the following rule:
before.insert check the REST connection if this is OK the record is saved else the record is not saved.

But how could I know the connection result if the call to callout from trigger must have @future and the @future method MUST be static and avoid? So, how could I return the connection result?
Best Answer chosen by Pedro Garcia G
Pedro Garcia GPedro Garcia G
Solution: lightning:recordViewForm and lightning:recordEditForm. Validate from JS before going to the server.

All Answers

Hemant_SoniHemant_Soni
Hi,

As per my understanding you should check if you get Status Code == 200 it means Call out is Successful and your API key is correct else update CONFIG__c  record with error Message in any Description Field.

please let me know, is this make sense or not. 

Thanks
Hemant
 

 
Pedro Garcia GPedro Garcia G
You're right but how I pass to the trigger the connection result if the @future method MUST be static and void.
Pedro Garcia GPedro Garcia G
I can not reach now my Scratch or Sandbox... there is something wrong in the connection.

I need to pass the result to the trigger because in the requirement says:
I create a Trigger in the CONFIG__c object with the following rule:
before.insert check the REST connection if this is OK the record is saved else the record is not saved.

So, the connector must tell to the trigger if the connection was OK (200) or not.

If there is another way to do... let me know
Thanks
Pedro Garcia GPedro Garcia G
Solution: lightning:recordViewForm and lightning:recordEditForm. Validate from JS before going to the server.
This was selected as the best answer