Questions tagged [insert]

Using insert DML, you can insert new records and commit them to the database.

Filter by
Sorted by
Tagged with
11
votes
3answers
17k views

How to insert reports/dashboards inside a lightning component?

I'm facing issues in inserting reports inside the lightning component. As in VF pages we have analytics report tag or iframe..but in lightning i'm not able to find a solution. If any body has done it.....
8
votes
1answer
14k views

Inserting test record with record type

I'm trying to create a unit test where a I insert a record with a specific record type Student_Records__c endterm = new Student_Records__c(); endterm.School__c = schl.id; endterm....
7
votes
1answer
2k views

Inserting Accounts and Contacts Simultaneously

Trying to insert a new Account and it's Contact (maybe multiple Contacts?) at the same time. While researching this, I've come across various posts that are close to the solution, such as: ...
6
votes
0answers
175 views

Why inserting a user object and making callout in a test throws CalloutException in Production?

I stumbled upon strange behavior when executing tests on deployment to production organization. In the test, I first insert a User object, some other objects and then as the last one, a CampaignMember ...
4
votes
2answers
4k views

Create static resource with apex code

Is there a way to create a StaticResource within a Apex code. this the code i am doing: StaticResource sr = new StaticResource(); sr.Body = file; sr.Name = 'testLicence'; ...
4
votes
1answer
10k views

Inserting Records using a lightning component

I am looking to make a lightning component to insert my Transaction__c object records against all relevant Contracts pulled back requiring action. As it stands I am returning all of relevant contracts/...
4
votes
1answer
4k views

INVALID_FIELD, Foreign key external ID not found - Inserting Related Records via External Id

I am trying to insert related records via an External Id. i am using an approach described here where we create an empty parent object with the same external Id like the "real" parent. It is a self-...
4
votes
2answers
805 views

Adding new values to Custom Picklist (PHP Toolkit)

I'm using the PHP Toolkit for integrating a web application with my Salesforce account. I have this custom object: Individual__Choice__c that contains this custom Picklist: Primary_Option__c This ...
3
votes
4answers
1k views

|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object on my Apex Trigger

I'm kind of new in Apex development and I'm writing a before insert, before update trigger to a custom object that is going to be upserted through an API integration. Is very basic code but I don't ...
3
votes
2answers
684 views

Remote Objects: Insert an array of objects

Is it possible to insert an array of objects using Remote Object Model? Here's my code: <apex:remoteObjects jsNamespace="romodel"> <apex:remoteObjectModel name="Stock__c" jsShorthand="...
3
votes
2answers
2k views

DML not allowed on User

I created some test users using the following apex code which worked perfectly fine: list<User> abc = new list<user>(); for(integer i=1; i<3;i++) { abc.add( new User( ...
3
votes
1answer
100 views

Does locking of account lock related contact during insert?

I have a WSDL Apex service that consumes XML and creates a series of objects. XML received and parsed, queries for and finds a single account "Potential Customer" to relate potential customer ...
3
votes
0answers
78 views

First event/event relation insert taking a while

I have an application that inserts events and event relations in an org's database and has a loading icon to prevent the user from doing anything until the event and relations are properly created and ...
2
votes
1answer
4k views

Apex Trigger giving “cannot specify Id in an insert call: [Id]” error

I'm pretty new to Apex and writing a simple trigger for when an account submits a form on our website (tracked on the formSubmit__c object) to create an Opportunity and am getting the following error ...
2
votes
3answers
477 views

Trying to get Code Coverage on my apex Class

I'm trying to get code coverage on my class to no avail. Any assistance would be greatly appreciated. I'm sure there is a better way to write my class but just trying to get the end user his request ...
2
votes
2answers
817 views

Lead before update runs on insert

I have a fresh dev org, with nothing at all in it other than this one trigger that is below. When I create a new lead, this trigger is ran. (ie, I put the new leads name as John Smith and Company as ...
2
votes
2answers
2k views

Insert data to custom object with relationship using external Id

Good day everyone, I have installed an npsp package and then I created a visual force that will save a new affiliation . I've tried to used an external Id to save the data. I've already tried saving ...
2
votes
1answer
154 views

Uncommitted work in tests / Preparing for callouts

I have the following scenario in some unit tests: I need to create some data with inserts I need to invoke a method which performs a callout The test fails with the System.CalloutException: You have ...
2
votes
1answer
771 views

Trigger to insert new record not firing

I'm trying to create an Apex trigger that automatically creates a new record when some requirements are met. We have a custom object, Vendor Issues, which we would like to have new records created ...
2
votes
2answers
56 views

How to update existing records and upsert new records

I want to update existing task records but a new record gets created instead . What am I doing wrong. Apex: public static void Activities(List<Account> accounts) { Set<Id> persAccIds = ...
2
votes
2answers
618 views

Error: Before Insert or Upsert list must not have two identically equal elements

Im getting above error when I try to add some custom records to a list and insert it later. Here's what Im doing. From the following code, I call a method from a different class (SetupBase) and add ...
2
votes
2answers
421 views

Why is this Trigger not working

I've a question with this trigger. I checked the register and it launch the trigger but is not doing anything. It doesnt show me the debug messages, even the first one. The idea is that when we are ...
2
votes
2answers
423 views

Error when I try to clone an object

I'm trying to clone an object, here is the code: @RemoteAction global static void cloneRow(String idProj){ System.debug('@@ clone: '+idProj); ConfigeroPSA__Expense__c oldExp = [SELECT Id,Name,...
2
votes
1answer
959 views

Storing json as a String field is giving wrong value

I have been developing an Apex Trigger where I build a json string from an incomming Event. What I do is serialize the event into the json at first, then deserialize it as a Map and add to it some ...
2
votes
1answer
640 views

Upserting objects in Apex: can I assert which have been inserted / updated?

I'm upserting a list of custom objects in an Apex controller that are retrieved on demand from an external source. My object has an external identifier field used to help the database call determine ...
2
votes
1answer
46 views

Unexpected behaivor: Database.insert(userList, false) is rolling back User insertion

I am attempting to insert two users with the database.insert method. One user that should work, and another that is missing required fields. // Create two users, one of which is missing a required ...
2
votes
1answer
27 views

What effect does FOR UPDATE have on pending inserts?

FOR UPDATE will lock a row to prevent other clients from accessing it, as is well documented. Does FOR UPDATE have an effect on pending inserts from concurrent clients as well? For example, assume ...
2
votes
1answer
2k views

REQUIRED_FIELD_MISSING & FIELD_INTEGRITY_EXCEPTION on PricebookEntry Insert

I want to use standard price for the Pricebook entry. PricebookEntry pbe = new PricebookEntry(Pricebook2Id='01sN00000002OTsIAM', IsActive=true, Product2Id='01tN0000004JGeuIAG', ...
2
votes
2answers
2k views

How do I scalably run Apex after a small delay so that all related objects exist?

I'm trying to run Apex code that runs a little while after custom objects are created. The problem is that I have a few systems inserting and updating data when a customer places an order in an ...
2
votes
1answer
41 views

Can't create relationship with Account and Custom object when using FF Unit Of work

I working on a class that needs to insert several records and create relationships between them, mostly to the Account object. I'm passing a deserialized JSON (WrapperRestZopaProviderRequest) to the ...
2
votes
1answer
643 views

Unable to insert records using Iterable Batch class

I'm trying to create an Iterable Batch class for inserting records. I'm able to insert my records in my normal class. I have created the Batch class and am trying to call it my current class in the ...
2
votes
2answers
1k views

update and insert not working

Upsert not working..update and insert not working..need help I have tried using the example given in salesforce visual force developer guide for upsert. It just inserts a new row. I tried in a ...
2
votes
0answers
617 views

Why doesn't Dataloader use specified 10k batch size when Bulk API is selected?

I have this sample CSV file containing 10,000 records (with 33 columns) I'd like to import it via Dataloader into Case object at my sandbox environment. I tried using these settings below with Bulk-...
2
votes
1answer
60 views

Record won't insert - Apex Trigger

I have created an apex trigger so that it will create a record for everyday of an opportunities contract, I have run the code without the insert statement and my debug shows it works fine. What am I ...
2
votes
2answers
864 views

Insert or update records dynamically through SOAP API's Partner jar

I am working on inserting CSV records to Salesforce. I usually do using Bulk API where the types are auto detected and mapped. However, I got into a scenario where I have to upload Documents or ...
2
votes
1answer
47 views

Problem with trigger execution on Opportunity batch insert

I've been dealing with this for a while now, and still haven't found a solution on the problem I am currently facing. So.. here is the situation. I have programmed a Trigger for the Opportunity ...
1
vote
2answers
170 views

Is my after insert trigger efficient and safe to port to production?

Recently I created an after insert trigger to update a field in my sponsorship object. it works so far in sandbox and has passed the unit test that I have created and has 100% code coverage. here is ...
1
vote
2answers
105 views

Why is my flag not working on maximum trigger depth exceeded

I have written a trigger for purchases if the purchase contains several of the same purchase detail items they should be summed up and merged as 1 purchase detail. When I use a before insert I get in ...
1
vote
1answer
558 views

Error: Too many DML rows: 10001

I have a question here, every time I run my code I first delete everything that is in the object, and then inserted a new list, when I try to do this simultaneously with the error ERROR System....
1
vote
2answers
325 views

APEX fields on inserted sObject

I have custom fields on my Account object. Some of them have default value, let say "Days__c" as number with default value 0. When I insert the object like this: Account account = new Account(Name = ...
1
vote
1answer
49 views

Create Child record when Parent's Parent Updates

I have to be able to create a child record called "seats" when the parent of the parent object of "Seats" changes. Teams -->Tables---> Seats So when Team changes, I need to be able to create Seats ...
1
vote
1answer
4k views

System.assertEquals for records in a list? Test class

I have a batch class that inserts Journal records after updating Account records... I am new to apex and cannot think how to test the inserted records in the test class. I have a list to get the ...
1
vote
2answers
155 views

Prevent insertion of records based on a condition

I have a zoo__c object. On Zoo__c , I have a field called firstName__c. I want to prevent insertion/updating of records if firstName__c has any of these characters at the end - "op" , "gp" , "kp". If ...
1
vote
2answers
1k views

How to get field values from VF page

I'm stuck with a really easy task. My VF page have StandardController and Extension. I'm using the standard fields for Task object : <apex:InputField value="{!Task.Client_Name__c}"/> So I ...
1
vote
1answer
79 views

How does a trigger behave

Assume I have written a after insert trigger on an object A. I do some manipulation inside my trigger and at the end I create 3 to 4 new objects , that is a related list in Object A(Master-detail ...
1
vote
2answers
2k views

Updating WhatId on Activity when Opportunity is Created

Here's something that I'm trying to do which I feel as though I've made it 75% of the way through. Right now let's assume I have the ability to generate an opportunity when a certain action is ...
1
vote
1answer
25 views

I'm trying to insert new record but it gives error as Line: 7, Column: 1 System.StringException: Invalid id: objcus.id

Apex_Customer__c objcus=new Apex_Customer__c(); objcus.Name='Test ABC'; insert objcus;//it will creat new customer records Apex_Invoice__c objnewinvoice=new Apex_Invoice__c(); objnewinvoice....
1
vote
1answer
25 views

Inserting dependent objects without using a loop

I have this issue. I have a list of Contracts and I need to create Cases and custom objects called 'Budget' that the Case needs to lookup. The code can be summarized to something like this for(...
1
vote
1answer
607 views

Upserting records using SFDX CLI for a object with no External Id

Below are the available data related commands in CLI. If I want to insert records using SFDX CLI, how to do that? force:data:bulk:delete -- bulk delete records from a csv file force:data:bulk:...
1
vote
2answers
120 views

Apex Test class for web-to-lead creation without OwnerId

I need to create an Apex test class for a Lead Apex Trigger that handles "before insert" of the web-to-lead inserts of Lead records that DON'T have OwnerId at the "before insert" time. Assigning of ...