I made a salesforce site and in its controller constructor I want to fetch a URL parameter value (the record id). The parameter will be found and it is the right record id. But when I am running the SOQL query, the record won't be found and this error occurs: List has no rows for assignment to SObject

Here's my code:

global with sharing class CampaignController {
global Kampagne__c kamp{get;set;}

global CampaignController(){
    Id id = ApexPages.currentPage().getParameters().get('kid');
    if(id != null){
        kamp = [SELECT Name FROM Kampagne__c WHERE Id = :id];



The object with the found id definitively exists. Is it a problem with rights on the site or what else could be the problem?

The site user has the right to read the object Kampagne__c and has also the right to read the field Name.


Controller class CampaignController is using with sharing key words. That means, that this class enforce the sharing rules that apply to the current user. So make sure, that running user has at least read access to record with that Id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.