Skip to main content

Questions tagged [database]

The tag has no usage guidance, but it has a tag wiki.

Filter by
Sorted by
Tagged with
141 votes
2 answers
11k views

Any reason to skip DML on empty lists?

In parts of my code I have DML statements with an if around to only do the DML if the list is not empty: if( !recordsToUpdate.isEmpty() ) { update recordsToUpdate; } Couldn't I just write? ...
Robert Sösemann's user avatar
28 votes
3 answers
11k views

Prevent insert to be rolled back even if class (later) runs into an exception?

I do some custom logging in my code, which basically means I write and update SObject records that contain custom log information. The problem is whenever an exception is thrown in my class, the ...
Robert Sösemann's user avatar
16 votes
1 answer
2k views

How can adding a Subselect make a SOQL query non-selective?

I have a SOQL Query with subquery that fails to execute because it is non-selective. I don't understand why and cannot interpret the results. All I know is that tearing parent und sub query apart ...
Robert Sösemann's user avatar
7 votes
2 answers
7k views

where do I use Database. Methods?

I m trying to understand where we use following Database.Methods. I know if we want to insert a record to an object we use DML Statement. What i want to know is why/where we use Database. methods. It ...
naruto's user avatar
  • 199
3 votes
3 answers
2k views

Database DML method executes twice in any record has been failed

I've been trying to leverage custom roll up functionality and found that Database methods is perfoming dml twice. First time it's inserting/updating all records and second time only ones that can be ...
Ilya Lepesh's user avatar
  • 4,125
1 vote
1 answer
585 views

How can I find problematic records in a dml action?

Let's assume I have a list of 100 new records that I want to insert, 10 of these records are missing information which will result in DML exception. Is there a way for me to create a list and include ...
Json's user avatar
  • 1,627
0 votes
2 answers
674 views

Rolling back a complete transaction

I have two object foo__c and zoo__c. zoo__c is a child of foo__c with a master detail relationship. I have validation rule created on Zoo__c with a condition that when the status__c field on related ...
SfdcBat's user avatar
  • 4,811
14 votes
4 answers
45k views

Only variable references are allowed in dynamic SOQL/SOSL

I'm trying to re-request an Asset from the database: asset = Database.query('SELECT ID, Price, Asset_MRR__c FROM Asset WHERE id =: ' + asset.id + ' limit 1'); But I get an error: Only variable ...
Sergey's user avatar
  • 551
11 votes
2 answers
535 views

How can updated SObjects/CObject be queried/retrieved without duplicate or missing records?

Another way to ask the question: Are SOQL queries transactional/atomic on the second level? I am writing a data integration with salesforce using the REST API. I want to retrieve a list of updated ...
edgartheunready's user avatar
11 votes
4 answers
11k views

Is manual Database.setSavepoint() and rollback needed on Trigger exception?

When something wents wrong in my synchronous trigger do I have to manually take care of this by before making a Database.setSavepoint() and rollback in the catch statement? Or is Salesforce.com ...
Robert Sösemann's user avatar
10 votes
1 answer
223 views

SOQL: (WHERE x IN(a,b)) does return 2 records, but (WHERE x = a OR x = b) returns only 1 record... Why?

I'm trying to retrieve some ContentVersion records, but I'm having a lot of issues with it. After some research it seems as if the records are divided into two 'sets' as it were, and Salesforce in ...
Willem Mulder's user avatar
8 votes
2 answers
32k views

updating a records using external Id in Apex

I copied the product data to another object named foo. I used only the name and externalId of product to copy it to Foo object. Foo's external id matches with product's external Id. Some of my ...
SfdcBat's user avatar
  • 4,811
4 votes
3 answers
3k views

how to make sure update contact step in journey builder honors primary key?

I am trying to create one Data Extension that can be used to log all contacts going into multiple journeys and then use update contact event within journey to update row when a contact exist journey. ...
kl2's user avatar
  • 353
3 votes
2 answers
30k views

Problem with Database.update()

I have some accounts to update but some validation rules can failed. So to avoid this I use the Database.update() function to update accounts even if some DML exception occur. try { List<...
SF_user's user avatar
  • 3,616
3 votes
2 answers
921 views

How to rollback DML after catching exception in unit test

I have a custom business logic that will block certain profiles from editing/creating/deleting an account. Because of other requirements, mainly around Record Types, I can't use profiles and ...
Has Nah's user avatar
  • 175
3 votes
2 answers
197 views

Links to Documentation for Database.* DML Method? Gone from APEX Docs

So we've got the usual DML statements insert accts; and we've got the database class dml statements, e.g. Database.insert(accts, false). Had a team member ask me a question about the parameter ...
Ralph Callaway's user avatar
3 votes
2 answers
5k views

Database.Query does not return fields with null value

Hi i'm executing this query using Database.Query(query) Where query is SELECT field1__c, field2__c, field3__c FROM Object1__c On the current record, field3__c is NULL but when i query on the ...
gmemo's user avatar
  • 49
3 votes
1 answer
1k views

Salesforce DB query cache (how long?)

How long does Salesforce keep results of a query in its internal database. We know that the first execution of a query takes the longest. Subsequent queries are much faster due to the caching ...
dream3n's user avatar
  • 39
3 votes
1 answer
827 views

Which free/commercial Salesforce To SQL app should I use? [closed]

I am looking for an easy to use app to synchronize (one-way) Salesforce data to a SQL database. I don't need mapping functionality that products like Jitterbit, Boomi and Informatica offer for a lot ...
Robert Sösemann's user avatar
2 votes
1 answer
230 views

What would be an ideal use case where you would use sObject.addError() over savepoints and rollbacks?

I came across two methods of preventing errors while inserting, updating or deleting the records in salesforce. Let's say I am performing any one DML operation, and I want the transaction to stop if ...
Ayush Goyal's user avatar
2 votes
0 answers
161 views

Obtaining users data after accepting / allowing a Chatter Application

I'm slowly on the road to completing my PHP application, the final piece to my knowledge is figuring out how, after a user accepts the use of an Application (I think I'm using a remote app atm), to ...
ehime's user avatar
  • 530
2 votes
3 answers
6k views

execute apex batch only if not running

I have below trigger where I am executing a batch apex. I need to see whether the batch job is currently not running. Can someone help me here? Apex trigger: trigger BatchTrigger on ...
Testing_SFDC's user avatar
  • 2,950
2 votes
2 answers
7k views

Pulling data from data views for one business unit only using query

SO, I want to pull data from data views for our business unit only in marketing cloud. Currently, it seems like when I run a query something like: SELECT * FROM ent._Subscribers WITH (NOLOCK) It ...
kuml's user avatar
  • 573
1 vote
1 answer
97 views

'<<<' characters are lost in a field after saving to the database?

I have a field on a custom object before saving to the database as below: <span>>>> just some text <a class="Link" href="/55555555555AAA" >John Travolta</a> <<<<...
javanoob's user avatar
  • 8,907
1 vote
3 answers
162 views

Custom Save on New/Edit page - Is this valid code?

In my controller extension I have a custom save method that works for New and Edit scenarios also saves modified child records The below code works in all unit tests but starts to show strange ...
Robert Sösemann's user avatar
1 vote
1 answer
2k views

Error when calling Database.insertAsync (Status Code "ASYNC_OPERATION_LOCATOR")

I am experiencing some bizarre behaviour when trying to insert external objects. The following statement results in an error: Object__x o = new Object__x(Name__c='Test'); Database.SaveResult[] sr = ...
Mossi2's user avatar
  • 479
0 votes
1 answer
78 views

How to get records from sendable audience who did not make it to _SENT log without hardcoding the jobid

I have a DE extension where I have saved 1 record by querying: DE NAME: DataView_Job_DE Select top 1 JobID ,EmailName ,CreatedDate ,JobType ,JobStatus ,Row_Number() OVER (Partition by jobid ORDER BY ...
kl2's user avatar
  • 353
0 votes
1 answer
766 views

Setting database.savepoint in one method and rolling back in another method

I have three objects ObjectA, ObjectB, ObjectC. ObjectA is the grand parent, ObjectB is child of A & Object C is child of B. I'm providing a button on ObjectA page layout to create/edit records ...
Priyanka's user avatar
  • 1,909
0 votes
1 answer
822 views

Variable does not exist: portalUserInfo.conAccount.Id in Query

Please help with this error: String query = 'SELECT Project__c,' + ' Project__r.Testing_Submitted__c,' + ' Project__r.Project_Sub_Phase__c,' + ' Project__r....
Json's user avatar
  • 1,627