People who code: we want your input. Take the Survey
14

This should be doable by passing an argument of type ApexPages.Action to the component <apex:page standardController="Account"> <apex:form> <apex:pageBlock title="My Content" mode="edit"> <apex:pageBlockButtons> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> <apex:...


8

You can pass the standard controller to the component, allowing you to invoke its functions normally: public class ComponentControllerClass { public ApexPages.StandardController pageStandardController { get; set; } // Needed only because we are providing a second constructor public ComponentControllerClass() { } public ...


6

There are three main points, all of which are trivial. Inline DML Statements ... ... Require Less Typing insert records; // or... Database.insert(records, true); ... Cannot Be Shadowed public class Database {} // ... Database.insert will now fail to compile System.Database.insert(records); // grumble grumble Declaring a variable or class named Database ...


4

Governor limits are checked before any rows are modified, so the allOrNone flag has no effect. Simply trying to modify a record past the 10,000th row will automatically result in a governor limit being thrown, and the entire transaction fails. If you think you might hit a governor limit, it's important that your code check using the Limits beforehand.


4

Reason for Mix DML error sObjects That Cannot Be Used Together in DML Operations DML operations on certain sObjects sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these ...


4

Yes. The code as you've provided is not considered 'bulkified' because it will execute an insert for each acctId. You'd probably want to add the Contacts to a list, then insert that list outside of your for loop. i.e. List<Contact> contactsToInsert = new Map<Contact>(); for(Id acctId : acctIdList) { contactsToInsert.add(new Contact(...


2

Custom object for logging DML_Log__c with fields: SObjectType__c (type = Text) Name__c (type = Text) ID__c (type = text) RecordTypeId__c (type = Text) Utility method public static void logDmlDelete(Sobject[] sObjList) { DML_Log__c[] logInsList = new List<DML_Log__c>(); for (Sobject sobj : sobjList) logInsList.add(new DML_Log__c( ...


2

You can still use batch Apex - even if you're not iterating over record. For example, this would require you to create a start method returning a list of strings. The execute method would then take a List<String> as the scope parameter: global class MyBatchClass implements Database.Batchable<String>, Database.Stateful In short you just need ...


1

That's not how upsert works. It works by using Id, or an External ID, to determine if the record should be inserted or updated. You would need some sort of external ID field to work with: List<Account> newAcct = [SELECT Id, Name, BillingCity FROM Account WHERE Name = 'Acme']; Integer externalIdCounter = 0; for(Account c : newAcct) { c.External_Id__c ...


1

There was a workflow rule on user object that was updating the user object and since it is called from account trigger transaction, and updation of user is not allowed in same transaction as standard objects, this error is produced.


1

We need to do this on a large scale and the only solution which I found is using 'Enable Login Forensics'. The API which we used is LightningUriEvent: It detects when a user creates, accesses, updates, or deletes a record in Lightning Experience only. This object is available in API version 46.0 and later. I was able to retrieve data of sObject, timestamp, ...


1

When a record is created, it has a number of fields that are "stamped" by the platform. Two of these fields are CreatedByID (who created the record) and CreatedDate (self-explanatory). You can pull this information via a report, a batch job, APIs, ...


1

The inline DML keywords don't allow for partial success, setting headers (e.g. to send emails or bypass duplicate rules), etc. Use them when you don't need any advanced features of DML operations. They are typically best for controllers, unit tests, and other all-or-none DML situations. The Database methods should be used for advanced features (e.g. emptying ...


1

I found a working solution for doing DML from a continuation method. According to the documentation for Continuation Limits, An Apex method that returns a Continuation object can’t perform Data Manipulation Language (DML) operations. What I did to get DML to work from a continuation call was to execute another apex method in the same Javascript method ...


1

Yes you need to create data so that your query can fetch them and perform the calculation in code. Get Started with Apex Unit Tests I suggest you to check this trailhead module to get better understanding of test class and apex testing.


1

You can demonstrate for yourself by ruining this anonymous script: class MyException extends Exception { } try { throw new MyException('msg'); } catch (MyException e) { system.assertEquals(0, Limits.getDmlStatements()); }


1

Yes, you can throw custom exception inside a loop. Apex doesn't consider it as DML operation, since you are not performing a DML operation. There are separate exceptions for DML operation which Salesforce provides. Refer Exception Class and Built-In Exceptions


1

Yes you can write your own APEX rest API which will accept the Id List as parameter and ten can perform DML operation on them. This is how your class will look like which accept the parameter and perform ction on them. @RestResource(urlMapping='/Account/*') global with sharing class MyRestResource { @HttpPost global static String doPost(String name, ...


1

You need to move the User creation to a @future method. See also: sObjects That Cannot Be Used Together in DML Operations (Example: Using a Future Method to Perform Mixed DML Operations) Mixed DML Operations in Test Methods An example of how it might work would be something like: @future public static void createUsers(Set<Id> contactIds) { List&...


1

When you try to delete the record, you first need to fetch them. Code can be as simple as below (you can add conditions as needed): trigger ListUpload on ObjectA__c (before insert) { if(Flag.boolFlag){ Set<String> setNewRecordIds = new Set<String>(); for(ObjectA__c ce1 : trigger.new){ setNewRecordIds.add(...


1

BusinessHours can't be set up in unit tests. Best bet is to just set one up in the org and be done with it. Probably all your offices do have a common holiday like 1st January? Then to make your unit test code office-agnostic, you can do something like this: static Datetime addBusinessDays(Datetime start, Integer time, String office) { BusinessHours ...


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