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
dfiredfire 

Permissions Error on Deployment

When trying to deploy my custom controller and VF pages for our Sites site from Eclipse, when running the test cases I get the following error

StudentApplicationControllerTest.testController System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, entity type cannot be inserted: Person Account: []

According to the WSDL docs this is a permissions error as follows:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
You do not have permission to create, update, or activate the specified record.

This doesn't make sense as I am the System Admin and have permissions to all objects, fields, record types, etc.

 

Here is the getter that creates the Person Account record

 

 

    public Account getStudent() {
        if(student == null) {
            RecordType recType = getPersonAccountRecordTypeId();            
            student = new Account(recordtypeid=recType.id,web_submission__c=true); 
            //student = new Account(); 
        }
        return student;
    }

   RecordType getPersonAccountRecordTypeId() {
    	return [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
    }

 

 

 

This is preventing our move to production and is critical.

 

Any help is much appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
dfiredfire

Doh!

 

Of course, I forgot, I set the test to run as the website profile, which didn't have the right perms. Now it works.

 

Thanks.

All Answers

MandyKoolMandyKool

Hi,

 

Looks like there is some problem in your test method. 

Something is going wrong in your test method when you are trying to insert PersonAccount record.

 

Check your test method. Also you can post your Test method here.

dfiredfire

Doh!

 

Of course, I forgot, I set the test to run as the website profile, which didn't have the right perms. Now it works.

 

Thanks.

This was selected as the best answer
MandyKoolMandyKool

Gr8!!

 

If that sloves your problem please mark it solved!!

BialBial

Hi.

 
I am writing test code for trigger in case for sending email to contacts of case by updating or inserting any case field. But i am facing problem in it. Please help me to sort out this issue. Actually I wrote the following trigger and test code, also the error is given below.
 
Trigger Code
 
trigger sendemaildemo on Case (after insert, after update) {
 
final String template = 'Test';
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
 
Messaging.SingleEmailMessage message1 = new Messaging.SingleEmailMessage();
 
Messaging.SingleEmailMessage message2 = new Messaging.SingleEmailMessage();
 
Messaging.SingleEmailMessage message3 = new Messaging.SingleEmailMessage();
 
Messaging.SingleEmailMessage message4 = new Messaging.SingleEmailMessage();
 
 
 
message.setTemplateId([select id from EmailTemplate where Name =:template].id);
 
message1.setTemplateId([select id from EmailTemplate where Name =:template].id);
 
message2.setTemplateId([select id from EmailTemplate where Name =:template].id);
 
message3.setTemplateId([select id from EmailTemplate where Name =:template].id);
 
message4.setTemplateId([select id from EmailTemplate where Name =:template].id);
 
 
 
 
 
// Send single mail to contact of each updated case
for (Case uc: Trigger.new) {
 
Contact c = [select Email from Contact where Id =:uc.ContactId and Email!=null];
 
message.setTargetObjectId(c.Id);
message.setWhatId(uc.Id);
 
message.setToAddresses(new String[] {c.Email});
Messaging.sendEmail(new Messaging.Email[] {message});
}
 
for (Case vc: Trigger.new) {
IF (vc.Contactemail__c!=null){
Contact v = [select Email from Contact where Id =:vc.Contact__c and Email != null];
 
message1.setTargetObjectId(v.Id);
message1.setWhatId(vc.Id);
 
message1.setToAddresses(new String[] {v.Email});
Messaging.sendEmail(new Messaging.Email[] {message1});
}
 IF (vc.Contact2email__c!=null) {
Contact b = [select Email from Contact where Id =:vc.Contact2__c and Email != null];
 
message2.setTargetObjectId(b.Id);
message2.setWhatId(vc.Id);
 
message2.setToAddresses(new String[] {b.Email});
Messaging.sendEmail(new Messaging.Email[] {message2});
 
 
}
 IF (vc.Contact3email__c!=null) {
Contact d = [select Email from Contact where Id =:vc.Contact3__c and Email != null];
 
message3.setTargetObjectId(d.Id); 
message3.setWhatId(vc.Id);
 
message3.setToAddresses(new String[] {d.Email});
Messaging.sendEmail(new Messaging.Email[] {message3});
 
}
 
 
IF (vc.Contact4email__c!=null) {
Contact f = [select Email from Contact where Id =:vc.Contact4__c and Email != null];
 
message4.setTargetObjectId(f.Id);
message4.setWhatId(vc.Id);
 
message4.setToAddresses(new String[] {f.Email});
Messaging.sendEmail(new Messaging.Email[] {message4});
}
 
else {
}
 
}
}
 
 
Test Code.
 
@isTest
private class sendemaildemo {
 
    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Case caset = new Case ();
        caset.Origin = '2F5008000000IEE2g';
        caset.Status = 'New';
        caset.Origin = 'CheseTek'; 
        caset.ContactId = '0038000001Doy5g';
        caset.Contact__c = '0038000001Doy5g';
        caset.Contact2__c = '0038000001Doy5g';
caset.Contact3__c = '0038000001Doy5g';
caset.Contact4__c = '0038000001Doy5g';
 
insert caset;
 
 
 
 
    }
}
 
 
Error
in insert caset;
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, sendemaildemo: execution of AfterInsert
 
caused by: System.QueryException: List has no rows for assignment to SObject
 
Trigger.sendemaildemo: line 16, column 1: []sendemaildemo.cls/sendemail/src/classesline 37Force.com run test failure
 
 
Thanks in Advance!
MandyKoolMandyKool

Hi,

 

There are couple of issues with your code (anyways we will try to solve your test method issue).

 

Do following things in your test method.

 

1. Insert Contacts in your test method. ie. write a code to insert the dummy contacts.

    ie.

    Contact objCon = new Contact();

    objCon.Name = 'Test';

    insert objCon; //If you want to insert multiple contacts use list and then insert

 

2. change line 

     

     caset.ContactId = '0038000001Doy5g';
     caset.Contact__c = '0038000001Doy5g';
 
     to 
     
     caset.ContactId = objCon.Id;
     caset.Contact__c = objCon.Id; // and so on
 
3. If you have the template naming "Test" available in salesforce then use make use of "seeAllData" annotation for your    
     test method. syntax as follows
     
@isTest(SeeAllData=true)
public class sendemaildemo{
//Your code
}
 
Hope this will help you!!
 
Cheers!