Hot answers tagged

11

You have your DML statement inside of the for loop. So it is trying to insert the list each time through the loop. This will work fine for a single transaction, but the minute you do this with more than 1 transaction, it will fail. In the case of multiple transactions, the first time through the loop, it will work fine, as there is only 1 opp in it. ...


9

You need to set the Id not the name. First fetch the Id Id stExam = Schema.SObjectType.Student_Records__c.getRecordTypeInfosByName().get('Student Exam Records').getRecordTypeId(); and then assign it endterm.RecordtypeId= stExam;


8

If you have an External Id field on Account that you can specify, you can set the relationship via the Name Pointing Field (Account). String externalId = '<some_value>'; Account namePointingReference = new Account(ExternalId__c=externalId); Account parent = new Account(ExternalId__c=externalId, /*other fields*/); Contact child1 = new Contact(Account=...


7

You will have to go with MetaData API. Something as below - MetadataService.MetadataPort service = createService(); MetadataService.StaticResource staticResource = new MetadataService.StaticResource(); staticResource.fullName = 'MyResource'; staticResource.contentType = 'text'; staticResource.cacheControl = 'public'; ...


6

You're seeing recursion because your recursion guard is in the wrong place. When this gets executed: AankoopDetailTriggerHandler.isBeforeInsert(trigger.new); if(AankoopDetailTriggerHandler.aankRecursion) return; AankoopDetailTriggerHandler.aankRecursion = true; what happens is something like this: Insert goes off before ...


6

No, you have not properly bulkified your code. Bulkification 101's most important lesson is to aggregate filter values, query before your loop and put records into a Map, and update values after your loop. Set<Id> sponsorshipIds = new Set<Id>(); for (Opportunity record : trigger.new) { sponsorshipIds .add(record.Sponsorship_Contract__c); } ...


5

Change: aff.npe5__Organization__c = accReference; To upsert accReference; aff.npe5__Organization__c = accReference.Id; accReference is an Account sObject, you need the ID. Same thing goes for the contact record. UPDATE: After careful investigation and getting the idea of what you're actually trying to do, you need to set the __r relationship ...


5

A conceptual approach could be store the data you need as custom data-attributes in the <li> collect the data you need into a JavaScript object (I use jquery for DOM-operations like this - others here will crucify me for that) serialize the object into a JSON string pass the JSON string to another Apex method using an action in Apex deserialize the ...


5

A typical reason for this is that you have Lead Assignment rules. Once those execute, a new owner is assigned and hence the Lead object is updated. You can see this in the debug log if you enable Workflow INFO and Apex Code DEBUG Or, you may have workflow rules or Process Builder rules that do updates on the Lead. The object will have changed and per SFDC ...


5

You don't need a Query here. You can easily do this in Before insert and Before update event. trigger UpdateAssetImageurl on SymphonyIPM__Patent__c (before insert,before update) { for(SymphonyIPM__Patent__c objPatent : Trigger.New) { if (objPatent.SymphonyIPM__Asset_Image__c!=null) { objPatent.Asset_Image_Url__c = objPatent....


5

Your Case.Id values are null until your perform the insert with insert newCases. You should be performing two DML operations, as you do here, and only a single SOQL query. Right now, you're performing SOQL in a loop. You need to refactor your logic to look something like this: Iterate over Cases and accumulate Ids in a Set Query against Cases by Id, with ...


5

Please note that fields can be made required via other means which are difficult or impossible to detect. Validation rules, triggers, and Process Builder can all introduce errors when a field is not populated (sometimes more intentionally than others). Given the above, you can still iterate the describe to find which fields are practically required if you ...


5

Others have covered how to address the Null Pointer Exception (NPE for short). I'd like to cover how to determine the cause of an NPE. When debugging NPEs, I like to keep in mind the famous saying of Sir Arthur Conan Doyle's Sherlock Holmes when you eliminate the impossible, whatever remains, however improbable, must be the truth An NPE occurs when you ...


5

It is not possible to insert parent and child records with the statement when the records have the same SObjectType. You will need to insert any parents, then insert or update any children to populate the lookups. See also the below passage from the Apex Developer Guide (emphasis mine): Creating Parent and Child Records in a Single Statement Using Foreign ...


5

The 10,000 DML row limit is per transaction, not per operation. You can't update more than 10,000 rows from start to finish. If you need to do so, you'll need to use Batchable or Queueable methods to process more records.


4

I think your trigger doesn't even pass your first IF statement due trying to reference the record type name. You're doing c.RecordType.Name which means you're trying to access field on the parent object. In the trigger context you only have access to fields on the sObject that the trigger is running on. So in this case you can access RecordTypeId, but not ...


4

There is a Report Chart component that can be added to the lightning app builder, however, it is currently not available in the community builder. Documentation have a lightning component in the AppExchange which can be used in the Community Builder, however, it does still require some code/configuration to get it working, but it will handle the rendering ...


4

Your problem is on this line Account acc1=new Account(Name='nEW',Account__r.owner.firstname='gSS'); There is no relationship account__r.owner.firstname The relationship is account.owner.somefieldonUser and even so, when you insert an sobject, you can only instantiate fields directly on that sobject so what you need is: Account acc1=new Account(Name='...


4

Just a note on how to cover the catch block, my standard approach is to use a lookup Id for the incorrect sObjectType. For example, if you set busIntId to a User Id, then you should get a DmlException. static testMethod void testSave() { MyController controller = new MyController(); controller.busIntId = UserInfo.getUserId(); Test.startTest(); ...


4

Simply searching that error message would yield some highly useful information: Sometimes a developer needs to create a record and then update it with information provided by a Web Service. However, a Web Service Callout may not occur after a DML statement within the same transaction. To achieve the required action, the transaction must be separated into ...


4

If you cannot guarantee that a value is not null, you typically add a null check: MyObject__c record = myMap.get(someKey); if (record != null) { record.MyField__c = someValue; }


4

This is a per-transaction limit. You'll need to break your code apart by using Batchable, Queueable or some other technique to stay under the 10,000 DML rows per transaction limit. There's way to break this limit under normal conditions. A transaction includes all the code that runs from start to finish in a single request, so if you're deleting a lot of ...


4

You haven't provided much in the way of details here, but I'd suspect that your issue is with the date you're trying to set to Date_of_Visit__c I know that SOQL queries can handle date literals, but I don't think that the rest of Apex at large can. You should create an instance of the Date class using something like Date.valueOf(), and set your Date field ...


3

Ajax toolkit is a Javascript wrapper over SOAP based API .While ajax toolkit is a good option ,the problem with Ajax toolkit has been the no of API calls consumed .It will count against the API limit . The other option is to use Javascript remoting .Please take a look at docs. With javascript remoting you will need apex behind scenes and you can bulk ...


3

I don't believe it's possible (can't see any list methods in the API). So you only option if you want to use Remote Objects is looping on create - not a great way to do it. However, there is an alternative that has no more overhead than Remote Objects - the AJAX Toolkit. To include the library, you do this: <script src="../../soap/ajax/36.0/connection....


3

there is a developer blog post on this. It basically amounts to: let Apex Controller get Report Data by Report MetaData API process to your needs and return to lightning component render as needed you can also use some JavaScript charting liberaries General approach: Transforming Report Data for Lightning Component by D. Peter JS charting library, and a ...


3

You can do something like the following. There may be a better way to do this; however, this will give you an idea of how to do it. trigger activityCreatesOpp on Opportunity (before update) { //Create a set and map to hold our values. set<id> oid = new set<id>(); map<id, task> taskmap = new map<id, task>(); //Put ...


3

A couple of options: You could run a scheduled job every X minutes/hours or at particular times in the day to process batch Orders (if the processing is not time crucial). Inside your batch you'd query orders created in the last X minutes/hours and process them. If you do this, allow a minute or two gap, in case a new order comes in when the batch runs and ...


3

From what I can see you're using the metadata API to create/update fields, which is not supported via that API. In cases where you need to interact with your org's objects, apex classes etc. Salesforce offers a different kind of API called the Tooling API. Find out more


3

Use the Database.upsert static method instead of the upsert DML keyword: //failure (DML not allowed on User) upsert user ExternalId__c; //success Database.upsert(new User(), User.ExternalId__c, true);


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