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

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.

Related

New to Azure Event Grid - trying to react to *any* object being created, deleted or modified

I'm completely new to Event Grid, but have been tasked with creating a way to track anytime any object is created, deleted, or modified within a subscription (additional noise filtering to be added later). Does this sound like I'm on the right track?
Logic App -> Workflow Designer:
When a resource event occurs:
Resource Type - Microsoft.Resources.Subscriptions
Resource Name - (subscription being watched)
Event Type Item - 1
Microsoft.Resources.ResourceDeleteSuccess
Event Type Item - 2
Microsoft.Resources.ResourceWriteSuccess
What I'm completely unclear on is how to output the object deleted/created/modified. Like write to a log or send an email "X" object was deleted by Y user. If anyone has a clue on that, I would greatly appreciate it. Or if there is an easier way to accomplish this, rather than using Event Grid, I'm open to suggestions.
WAY-1
Here is my Logic App flow
I'm using Outlook 365 Connector with Send an Email Action
The Event Data gives whole information on What, When and Who created/modified/Deleted the resource.
Here is the screenshot of the mail that I received.
you can add as many events as possible by clicking Add New Item
WAY-2
You can add logs to your storage account and check the details from there as below.
WAY-3
You can check it in the logs from Overview pane which gives complete details on particular Run Triggers.

How to call Data Editor from Code, C1 CMS?

Under definition tree, I can attach event to open Data Editor for certain element.
However, I have no idea how to trigger the workflow to open the Editor for a given id.
I have a custom action URL which point to a custom ASPX (List of businesses about 50,000) in the console.
Now I want to trigger call the default data editor from the custom ASPX. Is that possible.
Yes you can. There is a few steps you need to take, but then you can basically mimic all console behaviors from your own aspx-page.
First of all you need to include the necessary C1 Console javascript frameworks on your page. Do that by calling ScriptLoader.Render("sub") and write the result on your page. You would also need to include this javascript on your page https://github.com/burningice2866/CompositeC1Contrib/blob/master/Teasers/Package/content/Composite/InstalledPackages/CompositeC1Contrib.Teasers/teaserConsoleFunctions.js - its some wrapper methods which are able to construct the javascript objects needed to call C1's webservice methods.
When that is setup you can trigger opening a Edit Workflow by calling the executeAction javascript method via a link containing the necessary ActionToken and EntityToken like this https://github.com/burningice2866/CompositeC1Contrib/blob/master/Teasers/Web/UI/TeaserHtmlHelper.cs#L65.
Its important to understand that everything in the C1 Console in based on these tokens. You don't edit something based on its id but always based on the EntityToken the something is represented by.
And what you want to do, whether its edit something or delete it, that thing you want to do is represented by an ActionToken. So to be able to edit something, you need an EntityToken for that something and a ActionToken for the Data Editor.

Concurrent update on record in Salesforce

In system I am developing, user can access particular page which is used to make DML operation on custom object. I want to fulfill following business case :
User A opens a Page made changes on page but did not click Save.
At the same time User B opens a page made changes and click Save. User B data got saved in record.
Now user A came and click Save. But as data is outdated I want to prompt user that "you are over righting the latest update. Do you want to continue."
Is there any faster out-of-box way available to achieve it ?
Assuming this is in a VisualForce page, you could check if the value has changed inside your Save method.
Query for the LastModifiedDate of all records you may change, and save that in your controller. This should be done in your controller's constructor and/or anywhere you re-load the record(s).
In the save method, first query the record(s) again to check if the LastModifiedDate has been changed. If it has been changed, prompt the user.
Assuming you are trying to insert a record into an object.
You can write a validation rule on that object. Check if that record is already inserted or not and show an error message.
Regards,
Naveen
autorabit

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.

Want to display results of a callout

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.

Resources