Want to display results of a callout - salesforce

When a user 'Saves' a Contact (for example), whether it's new or just updated, I need to:
Do an external callout using one of the Contact field values as a lookup
Display the results of the callout, so the user can make a selection
Update the Contact based on the user's selection display the updated Contact
I have found two aproaches, but have reached a point in both that I need to resolve.
Trigger Based Method
In the 'after' trigger pass the lookup string to a callback.
Update the Contact with the selection
Issues
How do you pass the lookup string or results to a visualforce page to display the lookup results?
When the user makes the selection and the update has been done, how do I move back to the updated contact?
Override Base Method
I found a discussion here that seems to suggests using overriding & redirection to someone asking about 'Edit'. I think this could also be done with the 'Save' button.
Issue
This is meant to be a deployable sollution, so I think that the override has to be set in code (I'm using the IDE) and not via Setup (or am I wrong?). I can't find out if this is possible or how to do it
Sorry for detailed question. Didn't want to just ask the wrong question (i.e. assume I know the best approach).
Thanks...

For the trigger-based method, you cannot change the built-in Save functionality, but (per your second solution) you can override the Edit button and recreate the Edit page with Visualforce, which would give you full control over the Save button and how you handle the callout and redirecting.
The release notes for Spring '10 indicate that standard-button overrides are now available for packaging, as they can be created through the Metadata API.

Related

Accessing CustomFieldDefinition metadata via tooling api

So, I've been attempting to gather picklist dependencies per Opportunity record type for my lightning components. I have been able to retrieve Standard Field dependencies by RecordType, but it the Tooling API will not return the custom field dependencies. Standard calls and queries will not work either, as they state that the field has no controlling value or dependency.
Given this information I suspected that there was a table that is hidden somewhere that contains the keys for the RecordType and FieldDefinition, hopefully with a nested Metadata object.
I found an Id in one of the parameters in the setup menu for a Record Type and Id.getSObjectType() on it. The table name is CustomFieldDefinition. However, it is not accessible via SOQL or the Tooling API.
Has anyone accessed this table? Or has anyone been able to retrieve the field-record type picklist dependencies on custom fields AND standard fields?Tooling API ResponseDebug Log with SObject Name
I think you're doing it wrong.
"Controlling field" would be another picklist or a checkbox for example, something you change during same edit action. If you have dependency to record type - in that sense it's not a controlling field. Sure, you change record type and picklist changes - but really everything would change, it should be a different page layout (different fields shown, marked readonly/required etc). There's a reason that record type change is not done on normal edit screen, you do it by clicking special link on detail view and then everything "explodes".
Have a look at "User Interface API" - set of tools meant to help your custom app (mobile? desktop?) steal recreate a normal page layout. This one might be especially useful: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values_collection.htm
There's even a Trailhead: https://trailhead.salesforce.com/en/content/learn/modules/user-interface-api (skim through whole set but especially read last module)
And since you mentioned Lightning Components - are you aware of these ready tools:
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_ui_api
getPicklistValuesByRecordType
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_generate_record_input_create
or maybe you don't have to code it all and stuff like <lightning-record-edit-form> with recordtypeid passed to it will solve all your problems
Have a look, if I didn't give you a working solution then at least you have some keywords to Google around. If you're still stuck - try to post a code sample as new question?

Show Opportunity related Contacts in Custom Object Field

I have the next issue.
I have a custom object called 'Application', and I have this requirement:
"Show all Contacts related to an Application. Create a field on Application object, must be read only".
I solve it with apex code. 'Application' has a lookup to Opportunity, Opportunity to Account, and all my contacts have AccountId, so this way, I get all the contacts using apex code in a trigger.
But, I've been ask to change this to a Formula field in Application object.
So, my issue is next. I'm not able to get all contacts with advance formula editor, because they're not part of any object. I have no master-detail relationship.
Does any one know how can I achieve this using configuration? I should not use apex code for this req.
Thank in advance guys.
I don't think you can do it.
In formulas / merge fields syntax there's no way to go "up, up then down" (Application -> Opportunity -> Account -> down to Contacts related list). There's also nothing that would let you loop through Contacts (and display what? Ids? Names? Emails?). Roughly speaking you can only go up through dots.
You might want to explore path of "cross object workflow" rules but I imagine that when I add a new Contact to Account it should somehow "spread itself" to all related Applications? There's no straight way to fire a workflow on delete too - so you'd eventually end up with inaccurate list.
I'd say trigger was a good solution. Maybe it ws unoptimized but if it has to be in a field - tough.
There might be a fairly simple way of achieving that by embedding a visualforce page within Application page layout.
This should be doable with pure Visualforce (so technically there will be no Apex code ;))
Something as simple as
<apex:relatedList list="Contacts" subject="Application__c.Opportunity__r.AccountId" />
would be a good start (if you want your own layout and not a rel. list - you should be still able to pull it off with <apex:repeat> or <apex:pageBlockTable>.
There's one BUT here: it's not a field, just a display trick. Forget about using it in reports, mobile applications etc.
Another way - would it be acceptable to be 1 click away from these contacts? You could make a report "Account with Contacts", filter it by Id of one Account and later use "URL hacking" to change the filter depending on from which Application you'll click it. This link could be either a formula field or a real custom button/link. Technically - it's pure config, no apex & VF.
You can read more about URL hacking at Ray Dehler's excellent post and specifically about dynamic Reports here or here.

Sales-force Custom Object Edit page layout and Button

We have a custom object say Sales form. On edit apge of customer object we need to add a button Save and Add Product(similar to One we can have on Opportunity page). User forget to add Product/SKU after saving the sales form
New Button(Save and Add product), will save the sales-form first and then depends on record type will open the related list(child object).
Say a Sales form is for Custom Program, after save,. it will open up Custom Program relate list.
If Record type is of Price Change Notification it willl open up related list of SKU detail..
Is this possible, please adivse, we have 9-10 different record type, and we don't want to re-write the application with visualforce and all customization. Re-writing with Visualforce page has some pitfalls.
As far as I'm aware, you can't replace the Save button as it's part of the Edit page and not the standard layout, so to achieve this with one button you'd need to write a custom visualforce page, this need not be complicated though — a simple custom controller which uses a standardController for management of the record would suffice.
You would call Save on the StandardController and then return a different page redirect based on the record type, the page itself would pretty much only consist of an <apex:detail> tag. If you want more details I can provide more.
If you really don't want to write any custom code or pages then you'll need to do this as a two step process, i.e. use the standard page and then have a custom "Continue" button which takes the user onto a custom URL based on the record type. I've just created a contrived version of this by doing the following:
1 - Define a custom formula field on the object, this should be of type text and can use a CASE() statement to determine the URL which the user will be taken to when hitting the button (note that this was made just for the sake of an example so it forwards to the accounts standard page for the record type 'Friend' and contacts page for 'Foe').
CASE($RecordType.DeveloperName, 'Friend', '../001/o', 'Foe', '../003/o', '')
Note the reason I use a formula field here instead of the doing this in the custom button is that for some reason you can't seem
access the record types by name when defining a custom button.
2 - Define a custom button for the object called "Continue" or something similar that makes sense for you. For my example I just used the Contact object, so I referenced the custom field on my record and specified the options shown here:
3 - Customise the page layouts used by your record types to include this new button and you should be done!

Making Related Models Optional

I have a form where a user can enter a location address as well as the utility companies that provide service to that address. The Utility data is associated to the building:
Location hasMany Utility
Solely within the context of the utility, the name field is required so there's validation indicating as much. Within the context of a location, though, any utility information is optional. The user can choose not to enter that data when entering a location which would simply indicate that they don't want to associate the location with any or all of the utility companies we track.
Using the FormHelper, though, the validation is detected and the field gets marked as required. I want to retain that validation for the instances where utility data is being entered independently, but remove the required indicator on the location form.
I know I can hack this in any number of ways (e.g. removing the required class via javascript, etc.), but I'm wondering if there's a clean way to do this using the Cake API. I haven't seen anything obvious, so I'm hoping someone else has been here and found a clean, simple solution.
Thanks.
You can either ask the user how many utilities they want to add before creating the form, or you can add the Utility record inputs dynamically using js (the later is more work to do, and not as error-proof as the former).
An example of the view (if you want to do it in 1 view):
if (empty($this->data){
// a form to ask how many utility records the users want to create.
}else{
// generate the form based on user input.
}
I assume you know what to do in the controller.
I would add a class to the form element that are optionnal, and use that class to override the "required" indicator.
In fact there is a Cake solution, use the error param
$this->Form->input('Model.field', array('error' => false));
To disable error message output set the error key to false.

Where do I add a trigger for "Notes and Attachments" in salesforce.com?

I cannot find where in the salesforce.com UI I can add a trigger on a file attachment. I can find triggers on almost everything else, but attachment seems to be missing from the list (even when I view source on the page and search it. Does anyone know WHERE I can put this trigger in?
There is no way to do it directly as Attachment is one of those "lesser" objects that salesforce really gets "protective" about in a random and biased way. The only "legit" way to do it is to use some external build&deploy tools such as Force.com IDE.
If however you are not a stranger to undocumented 'hacks' do the following. Go to any object's trigger list and click create new. In the URL locate entity query string parameter (e.g. entity=Case) and change it to Attachment (entity=Attachment) and press Enter. Newl loaded screen will accept Attachment trigger.
Using Eclipse (Force.com IDE plug-in), right-click on your project & select "New" > "Apex Trigger". In the dialogue window that pops up, there is an "Object" dropdown / picklist, choose the object you want from this list - "Note" or "Attachment" etc. - then choose the "events" you want to trigger to execute on.
NOTE: a best practice is only one (1) trigger per object since you cannot guarantee the order in which multiple triggers on the same object will execute.
Have you tried creating the trigger from, force.com IDE??
In my opinion it should be possible from there.
To write a trigger for attachment, there is no straight way to do it but you can do it.
By creating a trigger on other object for example create a trigger in contact object then the url of the current page shows
"https://ap1.salesforce.com/........./&entity=Contact" you have to change "entity=Attachment"
then the trigger will be created for attachment object.

Resources