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
ryan keidryan keid 

how can I call external api from leads custom field onclick ?

I wanted to create a button in the leads search view, what I found was a way to create a custom text field with formula HYPERLINK to open a visualforce page and then IMAGE function inside to show the image as button.

The problem I have is HYPERLINK or other functions will open into another page or will atleast reload the current page.

Requirements that I had to consider :
1. create a button for each row of leads in custom view or any view that on click calls our external api to do some task.

2. The page should not reload or redirect to some other page

3. It should be like point and click and done.

Since the above solution cannot work(I think), now I am thinking of creating a drop down field with a trigger to call api on field update.

If you can guide me how can I solve these requirements it will be of great help.If my first solution is not possible, please do provide alternatives that can be used in this case.

My biggest problem is I have never seen an salesforce app in production or used salesforce for a company or have any idea how pros do it. I wish there was some standards like I know I am creating hacks and tricks but is there a right way(developer standard) to do this.
Best Answer chosen by ryan keid
ryan keidryan keid
So in conclusion, It was not possible to call an api on click of a custom field.

Reason for this conclusion:
1. on page redirect you should not call external api or web services (salesforce recommendation)
2. functions can be used such as hyperlink that opens a vf page which calls an api and then redirects back to where user came from. but that means redirect.
3. Hard to maintain records and not feasible if you want to deploy to multiple orgs.

We ended up implementing lightning components and actions with modal popup and everything.

If any one needs any recommendations and what to do why not to do. reply here or ask in forums.

PS. Above are in context of a new developer. maybe pros can do it maybe not.

All Answers

@GM@GM
Hi ryan keid,

Its not possible to call api without redirecting to VF page using "custom text field with formula HYPERLINK " approach.
The best way is to call API from trigger using some field values (as you already thought to use dropdown field).
 
You can even call apex class from process builder instead of writing trigger.you can explore on outbound messaging against your requirement.

are you going to use REST or soap API? is it synchronous or asynchronous call?

Regards,
GM

 
ryan keidryan keid
Hi GM,

Thank you for your reply and guidance. It really help validated that it is not possible and that I am headed towards the right direction.

Regarding your questions,
1. It is a rest api we control, can also make it soap(only if necessary),
2. It can be a  asynchronous call, (I think i am not sure if i understand in the context of salesforce) but the api can be called once and be done. If possible i would update another field saying the task was completed sucessfully(I think that would make it synchronous ?), but i have other options too like sending a mail to user from the (REST api) server itself or maybe calling the salesforce api for that org and putting response in chatter.

I am just exporing possibilities.

other things that I have seen,
1. There can be action like edit, delete, change owner (maybe add one here).
2. I am looking into process builder and flows but dont understand them very well but those seem like a nice idea. 

hope you can help with these questions too;
1. what possibilities do I have other than dropdowns ?
2. One problem is that user needs to change value and hit save can this be skipped, like do something on change, on click hope you understand what I intend to do. a click and done thing.
3. Can I open a modal like standard button and on clicking okay, do the api call and show a message like a standard button "Add To Campaign" does ?


Any help and guidance will be greatly appreciated.

 
ryan keidryan keid
So in conclusion, It was not possible to call an api on click of a custom field.

Reason for this conclusion:
1. on page redirect you should not call external api or web services (salesforce recommendation)
2. functions can be used such as hyperlink that opens a vf page which calls an api and then redirects back to where user came from. but that means redirect.
3. Hard to maintain records and not feasible if you want to deploy to multiple orgs.

We ended up implementing lightning components and actions with modal popup and everything.

If any one needs any recommendations and what to do why not to do. reply here or ask in forums.

PS. Above are in context of a new developer. maybe pros can do it maybe not.
This was selected as the best answer