function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bob_buzzardbob_buzzard 

SOQL Join against junction objects problem

I'm encountering some rather odd behaviour with a SOQL query involving a join to a junction object.

 

I have two custom objects, Custom_a__c and Custom_b__c and a junction object for modelling a multi-multi relationship between them.

 

I have a list of ids for Custom_b__c objects that should exclude their associated Custom_a__c objects from availability.

 

The code in question is as follows:

 

List<Custom_a__c> available=[select id, Name from Custom_a__c where id NOT IN (select Custom_a__c from A_to_B_Association__c where Custom_b__c IN :excludeIds ) ];

 

 

I have a number of unit tests that check all the edge cases for this, and they are initially all working when run from the Force IDE or online.

 

However, after a period of time they will all suddenly fail.  I have plenty of debug in the unit tests that shows my test data is not changing between runs.  Even stranger, if I add an additional whitespace entry to the code above and save it back, the next run of the unit tests works fine. 

 

I also have another version of this code that carries out the same processing, but splits the SOQL into two queries, and the unit tests for this version never fail.

 

Has anybody else experienced this behaviour?  I've been looking through all the documentation and I can't see anything that is wrong with the SOQL.  I'm wondering if there are issues around using fields in the where clause of a join that aren't retrieved in the select, although that wouldn't explain why it works for a while and then goes wrong.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard
This was indeed the problem, and its now fixed.

All Answers

bob_buzzardbob_buzzard

Hmm.  Looks like I might have hit this issue:

 

http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=16937&view=by_date_ascending&page=3

 

the code in question that is failing in a weird way is being called from a visualforce controller.

bob_buzzardbob_buzzard
This was indeed the problem, and its now fixed.
This was selected as the best answer
Nagesh B 13Nagesh B 13
Hi Bob,sorry to ask Question in the answer.  Is any way to insert document by using apex code directly without VF? i have One URL which download the pic into my local system, that URL contains  only string which refer to the external system. i wanna save that image into under salesforce document record. for that i have written following code. 
 
 abc__x ab=[select downloadURL__C from ABC__x Where name__c='xyz.jpg'];
       
        Document document = new Document();
            document.AuthorId = UserInfo.getUserId();
            document.FolderId = UserInfo.getUserId(); 
            document.Body = Blob.Valueof(ab.downloadURL__C);
            
            document.Name=iosx.Name__c;
            document.contentType='image/jpg';
            document.IsPublic = true;
            insert document;

please help me on this.
HareHare
sfdcsfdc
Hi Bob,

can you pleae help me on below request.
https://salesforce.stackexchange.com/questions/175501/problem-displaying-saveing-data-in-vf-page-with-two-objects-compare-multiple-d
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000UXEWQA4