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
RajanJasujaRajanJasuja 

SOQL not returning result

Hi,
I am inserting an account and then selecting the same account using SOQL. Here is the code.
Database.saveResult[] insertedCompanies = Database.insert(companyList,true);
                Set<Id> successIds = new Set<Id>();
                for(Database.saveResult aRes : insertedCompanies){
                    successIds.add(aRes.getId());   
                }
                System.debug(successIds);
                List<Account> getAccounts = new List<Account>([SELECT Id, Name, Duns_Site_ID__c FROM Account WHERE ((Duns_Site_ID__c IN : dunsIdSet) OR (Id IN : successIds))]);
                System.debug(getAccounts'+getAccounts);
 When I run this code as a system admin System.debug(successIds); shows me an account ID in set and then query return the same record in getAccounts. But when I run the same code from a custom profile System.debug(successIds); shows me an account ID in set. But SOQL is not returning any result. My custom profile user can see the account which comes in successIds. Which means he do have access of account. Any suggestion what could be the issue?    

Thanks,
Rajan 

 
Abdul KhatriAbdul Khatri
Can you check the Sharing Settings for Account and Contact?

Setup => Security Controls => Sharing Settings

If it's Private, this likely be the cause you don't see results in the SOQL as the owner of the Acccount is not shared.
RajanJasujaRajanJasuja
It is private. But I don't think that is impacting as this is Apex code and it run in system context until you add With Share. In my case I am not using with share. Beside that the user is able to see the account if I past the ID in URL. So he at least have red only access for the account.    
Abdul KhatriAbdul Khatri
hmm, I am not sure what should I make it from here onwards. Have you chcked the field level security for the field Duns_Site_ID__c
RajanJasujaRajanJasuja
I got th issue. As per the new Salesforce update you have to explicitly define the without Sharing in apex class if you are calling it from Lightning Componet .
Abdul KhatriAbdul Khatri
OK Good to know that, I didn't know there was a lightning component involved.