Written Very Basic APEX Class, How Can my Customers get to access it? - salesforce

I am very new to Salesforce Apex. I created a simple Apex-Class to get all contacts in the salesforce website.
I used javascript code to invoke that class as follows
function runApex() {
sforce.interaction.runApex('AccountRetrieval', 'getAccount', 'name=Rajeev', callback);
}
It's working fine in my laptop. But how can my customers get to access that class to get all their contacts ?

If you can't simply give them access to the contacts tab in the UI to achieve what you're after then you can create a visualforce page with a custom controller. In the controller, use SOQL to run a query for all Contacts and save the result to a list or map. You can then use this variable to pass the Contact data to the visualforce page. If you just want to dump the data to the page as HTML then you can use a list variable to hold the query result and an apex:repeat tag to generate the HTML on the visualforce page. If you want more control over how the data is displayed then you could also use the apex variable to pass the data to a javascript variable which you could then build your HTML from client-side in whatever way you like.
More detail would be needed to give you full steps on how to set this all up exactly how you want but basically you should use a visualforce page to give them an interface to run your apex code from. Access to that page can be controlled via profiles or permission sets.
If this page needs to be visible to people who do not have a user account to log into your org then you can use the Salesforce feature called Sites to expose content to them without the need for a login.

Related

update availableOptions for multiselect Picklist through Apex trigger

I have created a multiselect picklist which shows the list of users on a custom object. I want to update the available values on this picklist through trigger on User object whenever there is a new user created. I do not want to update the Chosen value. Also this is a field on a lightning page, not a vf or lwc or aura component. Is it a possible requirement? Please let me know if any further information required.
Field on Lightning page
enter image description here
Dynamically updating your org's schema based on data changes is both generally a bad idea and much more difficult than it sounds.
Your trigger would have to use Asynchronous Apex, such as a Queueable class, to call the Metadata API or Tooling API to update the picklist values. To do so, it must be authenticated as an administrator, so you'd also need to set up a Named Credential and authorize it as an administrator. And then you'd have to write the moderately complex code to actually create picklist entries based on Users, decide what to do when existing Users/picklist entries are deactivated, and so on.
It is generally a better pattern to implement a custom UI component (like a Lightning Web Component) where you need to present a dynamic picklist-style interface that's driven by data.

can we create a pick list in lead page layout getting data from external api

I am trying to call an external api from salesforce apex class which will get all the products.so next i want to show these products as picklist in salesforce lead creation or edit page.I am not sure its possible or not.Any solution or workaround on these is mostly appreciated.
I don't see a way to do this on a standard layout.
I personnaly could do this in a Visualforce page. Probably you probably can do this in a Lightning page as well.

page objects in selenium webdriver

I have a question about page objects in selenium webdriver. our site is very dynamic with lots of ajax and various authentication states. How to define each page object BUT lets say I have figured that out and defined several page objects that represent our site.
How do you handle crossing from page to page? So I get a page object for my home page and one for my account page and one for my results page. Then I need to write a test that traverses all my pages to simulate a user performing multiple actions.
How do you obtain a HomePage object to create a new use, then get a account page object to go perform some simulated user actions and then get a result page object to verify those actions? Can it be done in a single script?
this question is similar to one posted here, which may have an answer to your question: Selenium Page Objects

Server side rendered templates for AngularJs

I am building a complex web page, that has many users/groups/permissions where user can see all/some/none of the object of specific type according to the ACL (using Symfony2 and Symfony2 ACL).
What am I dealing with now is that I don't want to show every UI element in the frontend and just throw 403 error if user does something that he has not permission for. Hidding elements that the user has no permission to see would be better for UX.
It is like if I show a product info page for the user, I don't want to show the EDIT/DELETE buttons, if user does not have permission for doing that on this product or all products (class scope permission).
With Twig and server side rendered templates it would be easy as adding bunch of permission checks in template
{% if is_granted('EDIT', product) %}
<button>Edit product</buttom>
{% endif %}
But how to handle this in clientside with AngularJs?
What I was thinking is the following:
Create a controller method that serves Twig templates rendered server side for AngularJs. This takes a parameter of id identifying the object, which the user must have permissions on in order to see the EDIT/DELETE buttons rendered in the template (Twig and is_granted() handles this serverside)
User ask to view a specific product /product/1. The router templateUrl would be /templates/product/view.html?object_id=1, where object_id identify the object, that should be used while rendering templates serverside to grant or deny rendering ui elements.
The product JSON is then fetched and put in the template, which has already been rendered serverside, and has some Angular {{ }} waiting for product data to be placed in.
Are there any similar cases solved using other serverside technologies that you are familiar with and can be taken as an example to lead me on my way to success?
In our project client side Angular code is enough.
Back end wont ever send any data to front end user have no permission to view/access. (403)
Front end present login page to user with witch user can authenticate. Front end then send provided credentials to Back end, which is responsible for actual checks.
Back end will provide Front end with user role/access right/privileges. If those are more complex dedicated API endpoints will be provided. (Fe: Can user access this? Be: No. Fe: that? Be: Yes, but not delete. etc.)
Front end will use if's on data returned from Back end to conditionally render UI parts.
Do note that I use back end and front end, as described technique is framework agnostic and will work with pretty much any.
For Angular we created CurrentUser service that had is('role_name') that would return true if user had assigned role, false otherwise. ng-if or plain old if(), then where used to conditionally render html tags/data.

Prepopulate fields in Salesforce.com

I have a doubt, i've been working with salesforce for a while and now i have a requirement from a customer.
They need that some custom fields be populated with a value of parent object, making some research on stackoverflow, i found this post, but this isn't working for me because my project is a manage package and when this is installed on a another salesforce instance the id of custom field change.
if someone could help me, I will be grateful.
Thanks!.
I can't see any way of doing the same as that post without using the IDs, I was thinking you could route via a VF page and build up the URL in the controller but it doesn't seem as though you can get the IDs of fields, just their type etc..
I think the best you could do in this instance is to override the default new recordpage with a visualforce page. In the constructor of your controller you could then loop through the page parameters and pre-fill the corresponding fields on the new record before it's displayed on screen. Using fieldsets or just an <apex:Detail> component would keep the level of effort down and also maximise the flexibility of the page for the end users.

Resources