13

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 ...


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> ...


10

jordan's trigger is good in concept, but would probably violate Governor Limits if it were executed in bulk. A good design principle is to avoid having database operations inside of for loops, to avoid running lots of queries. Here's a modified form which allows bulk operations: trigger campaignmember on CampaignMember (after update) { // Query for ...


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

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 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 ...


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 would suggest that best practice is typically to not re-assign ownership of all records across the board. The fact that a record is owned by a disabled user is not in itself a problem. If you're using that user as a generic "data admin" type user then I'd suggest you create a user for that sole purpose and re-assign all records to that, then you never have ...


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

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 ...


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

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)


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

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

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 ...


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

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 ...


5

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


5

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) ...


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 : ...


5

Unfortunately this cannot be done using the REST API. What you need to use instead is 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 on how to use it. If you are trying to do this in Apex, there is an apex ...


5

Triggers are supposed to work that way. They do not pre-populate data on the screens but only update it during the transaction. Out of the box, you will not be able to pre-populate data. If you can create some lightning component, then you can utilize force:createRecord event here which lets you to open the standard screen for record creation with an option ...


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