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
newbie2010newbie2010 

User generated exception

I wasn't sure where to post this given the amount of info involved.  I have created a custom "log a call" page using a vf page attached to a button in the account layout.  I have this setup and running correctly in my sandbox environment when I am logged in (system admin).  When I login as anothe user it works correctly as well, but when I have a user login directly to the sandbox to test it generated the following exception...

 

Force.com Sandbox

Apex script unhandled exception by user/organization: 00540000000oRuq/00DQ0000000Db4h Source organization: 00D40000000Iqhe (null) Visualforce Page: /apex/Log_A_Call_in_Chatter

 

 

caused by: System.QueryException: List has no rows for assignment to SObject

Class.LogACallControllerExtension.getAccount: line 8, column 17 External entry point

 

Since this acutally posts items in Chatter, I don't want to move it over to production yet since I don't want any bogus information in our production org from testing to make sure it is working.  The vf page, controller and button URL are as follows...

 

<apex:page standardController="Task" extensions="LogACallControllerExtension" showHeader="false" sidebar="false">
<script>
  function refresh(){
   window.close();
   }
</script>
    <apex:sectionHeader title="Log A Call for..."/>
    <apex:form id="pageForm">
        <apex:pageBlock title="{!account.name}" mode="edit">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}" onclick="refresh()" />
                <!--<apex:actionSupport event="onclick" action="{!CreatePost}" /> -->
                <apex:commandButton value="Cancel" action="{!cancel}" onclick="refresh()"/>
            </apex:pageBlockButtons>
            <br />
            <apex:pageBlockSection title="Call Information">
                <apex:inputField value="{!Task.Description}" style="width:400px;height:100px;" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public with sharing class LogACallControllerExtension {

    public Task task {get; set;}
    public String CallInfo {get; set;}
    ApexPages.StandardController controller;
    
    public Account getAccount() {
         return [SELECT Id, name from Account
             WHERE Id=:ApexPages.currentPage().getParameters().get('what_id')];
    }

    public LogACallControllerExtension(ApexPages.StandardController controller) {
            task = (Task)controller.getRecord();
            task.whatId = ApexPages.currentPage().getParameters().get('what_id');    
            task.subject = 'Service Call';
            task.type = 'Call';
            task.status = 'Completed';
            task.activitydate = Date.today();
//            task.description = CallInfo;
    }
    public PageReference Save()
    {
        FeedItem cpost = new FeedItem();
        cpost.ParentId = ApexPages.currentPage().getParameters().get('what_id');
        cpost.Body = task.description;
        try{
          insert(task);
          insert cpost;
          }
        catch(System.DMLException e){
          ApexPages.addMessages(e);
          return null;
          }
          return(new ApexPages.StandardController(task)).view();
    }
}

 

/apex/Log_A_Call_in_Chatter?title=Call&what_id={!Account.Id}&followup=1&tsk5=Service Call&retURL=%2F{!Account.Id}&tsk3={!Account.Name}&tsk10=Call

 I am guessing there are some rights involved, but I wasn't aware that the system sees us differently when logged in as someone compared to that person logged in themselves.  Any suggestions on improvement to the code is welcomed as well.

Best Answer chosen by Admin (Salesforce Developers) 
newbie2010newbie2010

Taking the "with sharing" out of the class fixes this issue, but I still don't understand why it sees things differently.

 

I also am curious as to refreshing the account page where the button was clicked.  Is it possible to refresh or reload that page from the page generated by the button?

All Answers

Ankit AroraAnkit Arora

I don't know but I am quite sure the user logged in which is NOT a system administrator has a different profile and

 

ApexPages.currentPage().getParameters().get('what_id')

 is returning null. So just make sure that profile of that user is having CRUDE (Create,read,edit,delete,update etc) rights for account object.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

newbie2010newbie2010

Taking the "with sharing" out of the class fixes this issue, but I still don't understand why it sees things differently.

 

I also am curious as to refreshing the account page where the button was clicked.  Is it possible to refresh or reload that page from the page generated by the button?

This was selected as the best answer