Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Make your voice heard. Take the 2019 Developer Survey now

Questions tagged [trigger]

A trigger is a feature of the Salesforce platform consisting of Apex code that executes before or after DML operations.

5
votes
3answers
546 views

Field Describes in a Trigger causing scalability problems

I have a trigger (simplified sample code below) that is using field describes to determine what fields were changed to conditionally update some other field on the same record. The problem is that ...
2
votes
2answers
735 views

Required fields missing in trigger error. Why?

I have created a trigger to add a custom Milestone__c object to a Case on case creation. I have assigned values to the two required fields, which are Case__c and Start__c, but I am still get the ...
0
votes
3answers
6k views

GROUP BY Clause SOQL

How do I create a SOQL GROUP BY using custom field? For example: SELECT id, name, Cultura__c FROM SC_VPM__c GROUP BY Cultura__c This returns an error: MALFORMED_QUERY.
1
vote
1answer
1k views

Mail merge templating functionalty rebuild for custom object

I want to build more or less the same functionality as the mail merge. I was wondering if there are any standard methods or classes that can aid me. I've made a custom object named "correspondance" ...
15
votes
5answers
6k views

What sObject properties don't cause triggers to fire?

I recently discovered that updating your Chatter profile image won't cause the User trigger to fire (for fields SmallPhotoUrl or FullPhotoUrl). I was wondering what other fields, when updated, won't ...
0
votes
2answers
2k views

Making Approval Comment Mandatory

Is it possible to make approval comments mandatory? There is one discussed here. http://christopheralunlewis.blogspot.in/2012/09/making-rejection-comments-mandatory-in.html I've a two step approval ...
11
votes
3answers
6k views

How to Search Workflow Rules or Validation Rules etc in Apex i.e. Metadata Search via Apex?

Recently I'm working on building something for developers/administrators - a handy 100% force.com app allowing to search metadata. Currently this app allows you to quickly search (from sidebar) custom ...
5
votes
4answers
1k views

Has anyone completed a Chatter to Chatter via Salesforce to Salesforce integration?

I have a customer with a salesforce to salesforce connection for Leads (only currently) to their partner and they would now like to include Chatter posts across the two organisations. This sounds ...
18
votes
6answers
4k views

Can I store information even if the trigger throws an exception?

I currently have a trigger which sometimes fails when new information is inserted from a 3rd party system. I can't simply check the logs as it usually happens during the night and it's not easy to ...
3
votes
4answers
3k views

Non-selective query against large object type in trigger

The Alert__c object has a Rule ID field, which is just text, and a lookup to the Master__c object. I have a trigger on Alert__c, which when runs after insert, update or delete. It collects the Master ...
2
votes
2answers
3k views

How to send VisualForce Email using a template from a trigger

I am trying to send an email from trigger using SingleEmailMessage. As of now, I am composing my email body using the method setHTMLBody inside the trigger itself and the email recipients are: user, ...
2
votes
2answers
810 views

Writing Triggers - Apex Test classes - testing in Sandbox with very little data

I'm curious how others test their code in Sandbox when they have a Production environment that has more than 100k records in one or more databases. In my example, we have 350k Leads, and I'm writing ...
13
votes
3answers
3k views

How to download a VF page as PDF and email it from a trigger?

I have a renderAsPDF VF page that takes an object id parameter as part of the URL string. It returns a PDF with some textual data and some images (e.g. <apex:image id="theImage" value="/servlet/...
3
votes
1answer
7k views

Compile Error: Comparison arguments must be compatible types

Can someone tell me why this error would show up in this canned code I am using from SF's dev site? Enterprise Release 12 of SF.... Error: Compile Error: Comparison arguments must be compatible ...
8
votes
5answers
1k views

Is there any way to invoke contact triggers on a person account?

Background: I have an org that uses person accounts and an appexchange package that does not support them. However when looking into why they're unsupported the only thing that does not work is that ...
6
votes
1answer
903 views

Simple Trigger, less simple testMethod; can't deploy (works fine in Sandbox)

This is scaled down code from SF's own examples on how to find dupe email addresses. I have purpose commented out the Alert for now. There is a more elaborate trigger (that also works in Sandbox) ...
-1
votes
1answer
1k views

is there any other method instead of feedobject.addError()

I want a user to be able to create new new record for an object, but then be shown a message and not the inserted record itself, is there a method I can use for displaying a message other than ...
22
votes
5answers
14k views

How can we disable triggers, Validation Rules and workflow rules in salesforce org. [on off - switch]

How can we disable triggers, Validation Rules and workflow rules in salesforce org. This becomes really needed and important when we are doing data migration(data imports) in salesforce. The way I ...
6
votes
4answers
795 views

In a trigger, telling the difference between a new Chatter File and a Link to an Existing one

I like using Chatter Files for Attachments because they are prettier and searchable. The downside is that, when you add one to an Opporutunity, you don't see it as an Attachment on the Account like an ...
11
votes
3answers
2k views

Is there any way to get changes to OpportunityLineItemSchedule objects?

This is kind of a weird request - so bear with me. I need to detect changes in the OpportunityLineItemSchedule. Ideally i'd write a trigger against it but SFDC doesn't allow triggers against this ...
1
vote
2answers
2k views

Trigger is not validate via data loader

Good afternoon everyone, I have two custom objects in my org where I'll call him here and Object1 Object2, Object1 is master detail. I created a trigger in Object2 where caught all of the X values ​​...
10
votes
3answers
4k views

Salesforce Trigger - “DML not allowed on RecordType”

I have created a trigger which is dependant on a custom record type existing. In my test for the trigger, I want to ensure that when this record type doesn't exist the trigger throws the appropriate ...
7
votes
4answers
3k views

Can't use getContent() in a batch, future method, trigger etc

I have a VF page which has a method in the controller that generates PDF and sends it out via email. It's all working fine when I trigger off the method from a custom button on the page, which is the ...
7
votes
2answers
4k views

Case Assignment Notification Suppression

I am trying to determine if it is possible to suppress the Case Assignment Notification email from within a Before Update Trigger. Or confirm that this is a newly introduced bug since I believe I was ...
10
votes
6answers
2k views

How do you unit test a trigger when you don't know the required fields?

This is another issue addressed largely towards app developers. Let's say I write an insert trigger. When I write the test case for it, what I would normally do is create a new object, insert it, and ...
14
votes
2answers
4k views

How do you write a unit test for a trigger whose only function is to make a callout?

What is considered a best practice for writing a unit test (to maintain code coverage) on a trigger whose sole function is making a callout (Which also means it has to use a future method)? Neither ...
14
votes
3answers
1k views

Batch Apex in AppExchange package and orgs with related triggers that call @Future methods

Here's the problem: when an org has a trigger that calls an @Future method, any batch Apex that fires that trigger will fail, since you cannot call an @Future method from an @Future method OR from ...
41
votes
4answers
13k views

Workflow rule causing trigger to fire twice

I need to be able to detect that the trigger execution is happening because of a workflow field update. There is a suggestion in the cookbook: Controlling Recursive Triggers But this solution is not ...
78
votes
8answers
18k views

Can we determine if the Salesforce instance is production org or a Sandbox org?

I am looking for the most efficient way of identifying the type of org (Production or Sandbox) via Apex code. URL scraping is not useful to me, since I'd like to get this information inside a trigger ...