+ Start a Discussion
Shailesh DeshpandeShailesh Deshpande 

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY error when page is launched from Site

Hi,

 

I have a button on a page, onclick of which i am creating tasks and attachments related to those tasks. This works fine when i launch the page from the salesforce org. However, when i use this page as a site page, i get the below error:

 

"Insufficient Privileges

Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []"

 

Below is my function:

      public void saveEmailAsActivity(String appId, Messaging.SingleEmailMessage email)
        {
            /* Start - Added on 12th September 2011*/
            User objUser = new User();
            String strUserName = 'test@sfdcsiteuser.com';
            objUser = [Select Id from User where username=:strUserName];
            /* End - Added on 12th September 2011*/
            
            //Create an activty related to Applicant.
            Task objTask = new Task();
            objTask.Status = 'Completed';
            objTask.whatId = appId;
            objTask.Subject = 'Email:' + email.subject;
            objTask.Description = 'Body:' + email.getHTMLBody();
            objTask.OwnerId = objUser.Id; //Added on 12th September 2011
            insert objTask;

            //Create Attachment(s) if present within the email related to the above activity.
            List<Attachment> lstAttach = new List<Attachment>();
            if(email.getFileAttachments() != null)
            {
                for(Messaging.EmailFileAttachment objEFA: email.getFileAttachments())
                {              
                    Attachment objAttach = new Attachment();
                    objAttach.ParentId = objTask.Id;
                    objAttach.Name = objEFA.getFileName();  
                    objAttach.Body = objEFA.getBody();
                    objAttach.ownerId = objUser.Id;
                    lstAttach.add(objAttach);
                }
                if(lstAttach.size() > 0)
                    insert lstAttach;
            }      
        }

 

Now if i comment out the "insert lstAttach" portion, the code works fine. However it gives an error only when i try to insert the attachment.  I cannot remove the "objAttach.ownerId = objUser.Id" line, because it gives me another error saying that the "Owner of the attachment must be the same as that of parent task" and if i keep that line i get the "Insufficient Cross Reference Entity" Error.

 

Can anybody help me with this?

 

Thanks,

Shailesh.

pankaj.raijadepankaj.raijade

try using "Without sharing" key work in teh class definition.

 

let me know if this works.

Shailesh DeshpandeShailesh Deshpande

Hi,

 

Thanks for your reply. The class already has without sharing keyword. So this wont work.

 

Thanks,

Shailesh.

 

 

Eric_SantiagoEric_Santiago

Where you able to resolve this. I'm having a similar issue.