Questions tagged [database]

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

Filter by
Sorted by
Tagged with
117
votes
2answers
6k 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? ...
25
votes
3answers
7k views

Can I prevent an insert to be rolled back even if my 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 ...
19
votes
1answer
2k views

How to best use the “Test Data Builder” pattern in a database context?

I need to setup test data in proprietary cloud platform (Salesforce.com) where I have no access to advanced testing frameworks. Besides that you can read my code example like it would be Java. ...
15
votes
1answer
928 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 ...
11
votes
4answers
10k 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 ...
11
votes
6answers
7k views

Printable ERD from Salesforce that you can Edit

I built a solution for a customer and I want to pull the ERD from the Salesforce instance and have the ability to edit it. I know there are a few tools and the Schema builder in Salesforce but none ...
10
votes
4answers
21k 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 ...
10
votes
1answer
2k views

Why does the documentation stipulate that a many-to-many object relationship requires two master-detail relationships?

In theory you can model a many-to-many relationship using lookup fields exclusively or in combination with a master-detail field. However the documentation only mentions master-detail fields. What ...
10
votes
2answers
377 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 ...
10
votes
1answer
183 views

FOR UPDATE returns old values

I use FOR UPDATE locking in a query but when the first execution completed, the second execution (started while records were locked) seems to use the old data set. I played around for a while and ...
10
votes
1answer
167 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 ...
8
votes
2answers
4k views

Can I tell how many records in a Database.QueryLocator()?

According to the documentation, in a batch a Database.QueryLocator can retrieve up to 50 million records. A maximum of 50 million records can be returned in the Database.QueryLocator object. If more ...
7
votes
2answers
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 ...
7
votes
2answers
10k 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 ...
7
votes
1answer
346 views

Database.DMLOptions - How to prevent Chatter Group Auto-Follow trigger from generating email

Currently I have a trigger which auto-follows specific groups in our organization when a new user is brought onboard. The auto-follow trigger feature works great! However, we have quite a few groups ...
6
votes
6answers
1k views

Most efficient (instant / no Batch) way to mark thousands of records as dirty

I have the requirement to store and retrieve the information that a set of arbitrary sobject records are "dirty" and need to be touch by asynch processes. I am talking about 10.000 to 100.000 records ...
6
votes
2answers
176 views

How to consolidate dates to parent object?

On Account object I have Custom field: Support_end_date I have a custom object called: license. On license I have a custom field called: license_end_date. Each license has a parent object: Account (...
4
votes
2answers
219 views

Values of formula fields using NOW() and TODAY() actually stored in the database?

Just for the sake of argument, if I had the following formula field: MyObject__c.FormulaField__c = DAY(TODAY()) What is the actual value of this field stored in the database, will the value ...
4
votes
3answers
2k views

What are the options for Data Storage size in salesforce instance is reached or near limit?

Hi All please share your experience related to Data Storage size in salesforce instance is reached ? Did you increase data size from salesforce (quite expensive option) or any other option like delete/...
4
votes
3answers
311 views

When should I start worring about the number of Records on a single object in a SF Org?

Just completing a project that has been deployed into a global SF Org. We have one object in particular that is likely to require a large number of records and is a related list on most pages. At ...
4
votes
1answer
1k views

Can Salesforce function as a “data warehouse?”

I am attempting to integrate on-premises software with our Salesforce Org. Our timekeeping system uses a PostgreSQL database to store time entries committed by staff. Salesforce's role is relegated to ...
4
votes
1answer
919 views

Database class commit

Why does Database class not provide commit method so that we can commit explicitly as well while in a transaction as we can do a rollback.
4
votes
0answers
2k views

Is there a simple way to generate a create table script from a salesforce class?

I am looking for a way to synchronize Salesforce data with a local database. At the moment I just want a pain free way of downloading the data. I've been playing around with importing CSVs from the ...
3
votes
2answers
16k 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<...
3
votes
1answer
565 views

How to know which Database.SaveResult instance corresponds to my SObject

I am currently trying to Update and Insert to collections of SObjects. I perform the actions(update&insert) separately, obtaining a Database.SaveResult Array as feedback. The problem is that I ...
3
votes
1answer
1k views

Can you query/write to a MySQL database from apex code?

Is it possible to work with a MySQL database directly from Salesforce? If not, is the main approach to create some sort of web service to sit in the middle between the two?
3
votes
1answer
2k views

Difference between Database.executeBatch vs System.scheduleBatch

I am curious to know is there any notable difference between Database.executeBatch vs System.scheduleBatch. One difference I know is, we can delay the batch execution in scheduleBatch method. However, ...
3
votes
3answers
944 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 ...
3
votes
2answers
150 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 ...
3
votes
3answers
2k views

Can I rollback a Before Insert trigger from an after trigger event?

Scenario: After an object is inserted/updated (can happen after any of the two) - I update an external system with that object's info - Object ID is needed - which is why I need the After Insert. ...
3
votes
1answer
784 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 ...
3
votes
2answers
125 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 ...
3
votes
2answers
289 views

External SalesForce Forms

Is it possible to create external SalesForce Forms that can populate fields in the same way as inside salesforce? We offer online teaching and the idea is that teachers, after every lesson, can fill ...
3
votes
2answers
127 views

Deleting Big Object Workaround Without Using Database.deleteImmediate

Known Issue for not being able to deletg Big Objects with database.deleteImmediate still open. This is the only method mentioned in docs to do this. Workaround to delete 1 X 1 is a joke. Any other ...
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 ...
3
votes
0answers
113 views

How can we keep our tasks accessible to view and report on while not having them count against the data storage limit?

The org I am working with right now is using 210% of its allotted data storage. Most of the storage space is taken up by tasks (over 31M records). Is there a way to decrease the data usage while ...
2
votes
2answers
3k views

Database Query Locator vs Simple Query

I want to know what is the difference between Database.QueryLocator() and simple SOQL Query i.e. List<Inventory__c> invent = [Select Id,Quantity__c,AccountId__c,Name,Expiry_Date__c From ...
2
votes
1answer
546 views

Database.Query Variable Does Not Exist

How can I get the field results from a dynamic database query to be available to be put into a list? Here is the code I have: //Query on the destinationObjectFieldName results List<sObject> ...
2
votes
1answer
348 views

Database.rollback() risks and alternative

I've inherited some complex logic that does several different DML actions within the same (fairly long) method and if there are failures I need to revert everything that's been previously done. The ...
2
votes
2answers
159 views

I'm building a database in unlimited version but I think i'm doing this wrong

I think I did this wrong? Can someone advice me? I basically paid a $250 month unlimited service to build a database but I would like to sell it on appexchange. So as I build, I realized that I ...
2
votes
1answer
2k views

SOQL Order by multiple fields with specific values

I have a problem with sorting data with SOQL query. I am sorting data with SELECT Id, Name, CreatedDate, Status FROM Account ORDER BY CreatedDate ASC; But i want to add one more field to sort with. ...
2
votes
2answers
2k views

Is it possible to not use an ExternalId field for Database.Upsert?

I'm trying to upser a list of Asset records via Database.upsert(List, externalIdField, boolean) and on the externalIdField, I want to pass the standard field 'SerialNumber'. List<Database....
2
votes
1answer
714 views

DML Database method is covered by unit tests, how to determine reason for no test coverage of the SaveResult variable?

The blue indicates test coverage. The red indicates uncovered code. Where would I find the cause for the uncovered code? public List<Opportunity> insertOpportunityAndDefineRelationships(...
2
votes
1answer
1k views

Database.DeleteResult.getErrors() question

I am trying to connect specific records that fail to delete in my batch job to their error messages. I thought my solution was working, but I checked the size of .getErrors() and it's size 1. My test ...
2
votes
2answers
4k views

Salesforce API for saving data in Salesforce database using any other language (Cakephp)

Friends, I am a web developer(Cakephp). I am working on the XYZ project. In that project I have many Contact forms example - contact us form, user details form, enrollment form etc. I developed that ...
2
votes
2answers
3k 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 ...
2
votes
2answers
1k views

How to remove deleted records from salesforce database memory?

3 days back I have created a report in my org and after some times I deleted that record ..even i deleted report from recycle bin as well Now it's been 3 days still that report present in salesforce ...
2
votes
1answer
4k views

How to get data type of any object's field in SOQL

how to i get datatype of any filed in SOQL?
2
votes
3answers
439 views

Backing up sf data in external DB [closed]

Hi I need to back up my sf org data into my local database. I am looking out for tools or any best practices to this at specific time intervals or regular time intervals. Can any one suggest what ...
2
votes
1answer
187 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 ...