14

Take a look at Triggers and Order of Execution. What you observed is the expected behavior. Here are the relevant steps. (3) Executes all before triggers. (6) Executes all after triggers. (9) Executes workflow rules (10) If there are workflow field updates, updates the record again. (11) If the record was updated with workflow field updates, fires before ...


12

When I've had need for this, I've always used the following pattern, which works out well: trigger X on Y (after insert, before update) { if(Trigger.isAfter && Trigger.isInsert) { update Trigger.new.deepClone(true, false, false); } if(Trigger.isBefore && Trigger.isUpdate) { for(Y record: Trigger.new) { ...


12

For a one time update, try using the Execute Anonymous functionality in the Dev Console. There, one can write and execute Apex code. Note that all the governor limits are still in place (e.g. limit of 10,000 records in DML calls). Since you mention you only have 2,000ish records to update, Execute Anonymous will he handy. Example: List<Account> ...


9

The default behaviour relates to 'new' records only, not existing - so yes expected behaviour. The statement that you have provided is SQL rather than SOQL. You can't issue SQL statements within Salesforce, you have to take the following steps: Retrieve the data using a SOQL query Update the data using a DML statement There are some governor limits that ...


9

You have an assignment expression, using the assignment operator (single equals =) where a Boolean expression is expected. if(Contact.Open_Opportunity_Count__c = 1) You should use the equality operator (double equals ==) instead to test equality. if(Contact.Open_Opportunity_Count__c == 1) See Understanding Expression Operators for the official ...


9

You cannot update more than 10000 records in a single transaction. It looks like you may be doing this in a VF page so you will have to write your VF page to check the status of a batch every so often and then do what you require when it is completed. You can use <apex:actionPoller> in your page and run a method to query the AsyncApexJob object to see ...


9

It's one DML and SOQL per 200 records or a single DML "chunk." To illustrate this, consider the following code: contact[] c = [select id from contact limit 5]; id accountid = [select id from account where ispersonaccount = false limit 1].id; c.add(new contact(lastname='test1', accountid=accountid)); c.add(new contact(lastname='test2', accountid=accountid));...


8

You should use the ISBLANK function instead of ISNULL. You get the wrong results for text otherwise. See this much better answer for more explanation ISBLANK vs ISNULL


8

Perhaps I'm missing something about your situation... But for this sort of problem I would usually run code like this multiple times from the developer console: Opportunity[] opps = [select Id from Opportunity where NewNumberField__c == null limit 100]; for (Opportunity opp : opps) { opp.NewNumberField__c = 0; } update opps; Raise or lower the limit ...


8

You should go with Process Builder. The beauty of process builder is one process can handle multiple criteria updates and all of them will be in a single process like the one you have now. Process Builder is the future! If you see the new Professional Salesforce Editions, they don't have workflows anymore, they only come with Process Builder. Process ...


7

I think this answers your question where MyField__c is updated from Grandparent to Parent upon grandchild insertion: trigger updateParentwithGrandparent on Grandchild__c (after insert) { // Get a list of all Parent Ids Set<Id> parentIds = new Set<Id>(); for (Grandchild__c gc : trigger.new) { parentIds.add(gc.Parent__c); }...


7

Assuming you want to take the first 5 digits from the zipcode field to use in the validation rule, you can use the LEFT function to do that. As per the Salesforce documentation, the LEFT(text, num_chars) function Returns the specified number of characters from the beginning of a text string. TRIM(LEFT(zipcode, 5))


6

You have 2 choices, one, switch it to Master/Detail and then use a roll up summary field or create a trigger to emulate the roll up summary field. The trigger would be on the demand object and every time there was a DML (insert, update or delete) the total would need to get recalculated for the parent release record.


6

With the comments you answered, the reason is because your contact__c is on the detail side of a master-detail relationship. In that case, the owner of your contact__c object will be the owner of the master object, thus there is no ownerId field on contact__c. Hope this helps.


6

Here is a link with similar solution. Requirement: Calculate Due Date from Start Date and Number Of Business Days Due Date = Start Date + Number of Days [excluding Saturdays and Sundays] An apex trigger to calculate the Due date on an insert or update is rather time consuming than just creating a formula field with some logic. The below formula field ...


6

Your friend is the BLANKVALUE function that if the first argument is null, will use the second argument as the value of the expression BLANKVALUE(Field__c,0) + BLANKVALUE(Field1__c,0) + BLANKVALUE(Field2__c,0)


6

You can just query the PricebookEntry records instead: Set<Id> entryIds = new Set<Id>(); for (QuoteLineItem item : trigger.new) entryIds.add(item.PricebookEntryId); Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>([ SELECT UnitPrice FROM PricebookEntry WHERE Id IN :entryIds ]); for (QuoteLineItem item : trigger.new) ...


6

As the other answer says, you can do this via the Tooling API if you want to use a REST call. You can find the details on their answer. The other option is to use the Metadata API which is a SOAP API. This stackexchange post has some example code about updating picklists using the Metadata API. The first link to the Metadata API docs should get you started ...


5

You can perform DML operations on records in after insert/after update triggers. You just cannot do it using trigger.old or trigger.new context variables. You will need to use a static hasRun boolean or something similar in the trigger handler to avoid and infinite recursion in your trigger.


5

The field updates occur "simultaneously", and therefore you cannot predict the behavior of the updates. Also, workflow rules are evaluated "simultaneously", meaning that one field update won't necessarily be visible to other rules, but you can choose to "re-evaluate workflow rules" to chain them together (up to 5 times). Specifically, Salesforce follows ...


5

Rather than creating "dummy" record types, which seems like a heavy handed way to identify the different incoming Email2case types, why don't you add different case origins to the picklist, and set three of these? If you navigate to Customize > Cases > Fields > Case Origin you could then add three new values to the picklist Refund X Refund XY Refund XYZ ...


5

Instead of a formula, create a new Date or Datetime field, and update it to NOW() via a Workflow Field Update or via a trigger, whenever you detect that the Checkbox value has been changed from False to True.


5

I am not sure how to interpret your trigger, but here is how I would find all Checkbox fields in Execute Anonymous: Set<Schema.SObjectField> checkboxFields = new Set<Schema.SObjectField>(); Schema.DescribeSObjectResult describe = Issue__c.sObjectType.getDescribe(); for (Schema.SObjectField field : describe.fields.getMap().values()) { // you ...


5

I think the error lies in these lines var action = component.get("c.account"); action.setParams({ "account": account }); try changing it to var action = component.get("c.saveAccount"); var account = component.get("v.account"); action.setParams({"account": account}); as I'm sure you know, the action needs to reference an AuraEnabled controller method, ...


5

well, one issue is with your testmethod - you need to requery the Contact to get the value set in the trigger Contact c = new Contact(LastName='x',MailingCountry='Angola'); insert c; Contact cRes = [select id, region__c from Contact where id = :c.id]; System.assertEquals('Africa',cRes.Region__c); also, although not related to your issue per ...


5

It would look something like this: {!requireScript("/soap/ajax/37.0/connection.js")} var newRecords = []; var c = new sforce.SObject("Invoice_Statement__c"); c.id = "{!Invoice_Statement__c.Id}"; c.Contract_Date__c = new Date("{!Invoice_Statement__c.Contract_Date__c+365}"); newRecords.push(c); result = sforce.connection.update(newRecords); window....


5

I advise you to implement this functionality declaratively. In this case, you simply need a Workflow Rule and a Validation Rule. I highly recommend you read Visual Development – When to Click Instead of Write Code (emphasis mine): Examples for Declarative Development versus Code Here are some use cases and examples for functionality that can easily be build ...


5

The trigger(s) (and it is both Trigger 'A' and Trigger 'B' in your example) are only being executed once after the workflow field update because that's how Salesforce has decided to make things work. If you go look at the official order of execution, you'll see the following (emphasis mine) If there are workflow field updates, updates the record again. If ...


5

Try this. AND( ISBLANK(TEXT(PRIORVALUE(InternalStatus__c))), NOT(ISNEW()) )


5

You need to perform a separate query to retrieve names. Salesforce doesn't return values from related object's fields, though it will not give you the error rather it returns null. Here is an approach: public static void setRecordName(List<Responsible_Party__c> newList) { Set<Id> Ids = new Set<Id>(); for(Responsible_Party__c r : ...


Only top voted, non community-wiki answers of a minimum length are eligible