• youji37
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies

I try to insert a record to CaseShare table with following trigger, but return error:

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger prmSharingTrigger caused an unexpected exception, contact your administrator: prmSharingTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: Trigger.prmSharingTrigger: line 14, column 13

 

Trigger:

trigger prmSharingTrigger on Case (after insert) {
    integer i=0;
    
    for (Case a : Trigger.new) {
        
        if(a.RecordTypeId == '012R00000008hE5'){
            
            CaseShare newCaseShare = new CaseShare(
                caseId=a.id,
                UserOrGroupId=a.LastModifiedById,
                CaseAccessLevel='Read'
            );

            insert newCaseShare;
        
        }else{
        //do nothing for other record type case.
        }
                
        i++;
    }
}

I use the following statement, want to get he record from ProcessInstances table, but it return.Don't know how to get the record from this table. And I want to know if this sql statement returns any record, can someone tell me how to do that?

 

 

ap=[Select CreatedById, CreatedDate, Id, IsDeleted, LastModifiedById, LastModifiedDate, Status From ProcessInstances where TargetObjectId =: a.id].Status;

Message Edited by youji37 on 05-13-2009 07:24 AM

 I use following code to invoke a approval process in trigger, the approval process will send an email to the owner's manager for approval, now the problem is when I update of insert the record, the approval will run twice, it will send two email to the owner's manager, but I only invoke it once as you can see in the trigger.

 

 

trigger autoApproveTrigger on Quote__c(after update,after insert) {
    for (Quote__c a : Trigger.new) {
        if(a.Quoted_Cost_Unit_Price__c < a.Field_Min1__c){
             
             Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
             req1.setComments('Submitting request for approval.');
             req1.setObjectId(a.id);
             Approval.ProcessResult result1 = Approval.process(req1);
             
        }else{
            //do nothing for other record type case.
        }
    }
    
}

 

 

I want to invoke a approval in trigger, I only know the approval name like 'Unit cost less than Field Min', but don't know how to invoke it in trigger.

 

trigger autoApproveTrigger on Quote__c(after update,after insert) {
    
    for (Quote__c a : Trigger.new) {
        
        if(a.Quoted_Cost_Unit_Price__c >= a.Field_Min1__c){
            //Unit cost_less_than_Field_Min.Quote(a.Id);
        
        }else{
            //do nothing for other record type case.
        }
    }
}
can someone help on it?

I try to insert record into caseshare object, get the following error.

Invalid id value for this SObject type: 500R0000001bUb5IAE: Trigger.prmSharingTrigger: line 14, column 22

 

 

my code is

   

for (Case a : Trigger.new) {
       
        if(a.RecordTypeId == '012R00000008hE5'){
           CaseShare newCaseShare = new CaseShare(
                id = a.id,
                UserOrGroupId=a.CreatedById,
                CaseAccessLevel='Read'
            );

        insert newCaseShare;

I'm going to create a trigger on case object, this trigger should only invoke when the case're record type is "XXX", "XXX" is one of the record type of case, can someone help me figure out the code to identify the report type is "XXX". the following script doesn't work.

if(Trigger.new[i].RecordType == 'Partner Case'){

I try to insert a record to CaseShare table with following trigger, but return error:

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger prmSharingTrigger caused an unexpected exception, contact your administrator: prmSharingTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: Trigger.prmSharingTrigger: line 14, column 13

 

Trigger:

trigger prmSharingTrigger on Case (after insert) {
    integer i=0;
    
    for (Case a : Trigger.new) {
        
        if(a.RecordTypeId == '012R00000008hE5'){
            
            CaseShare newCaseShare = new CaseShare(
                caseId=a.id,
                UserOrGroupId=a.LastModifiedById,
                CaseAccessLevel='Read'
            );

            insert newCaseShare;
        
        }else{
        //do nothing for other record type case.
        }
                
        i++;
    }
}

I'm going to create a trigger on case object, this trigger should only invoke when the case're record type is "XXX", "XXX" is one of the record type of case, can someone help me figure out the code to identify the report type is "XXX". the following script doesn't work.

if(Trigger.new[i].RecordType == 'Partner Case'){