• Bryan Revelant 7
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 18
    Replies
Having an issue with the below test class. I have an insert trigger for the sharing object upon a field change. When the field next_step = submit then the code grabs a look up to user on the child, and gives the user visibility to the parent. 

I keep getting an error: 
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

Class.TestADRShareSubmitV2.ADRNonApprovalObjectUpdateChildRecordwithSubmit: line 136, column 1



@istest
public  class TestADRShareSubmitV2 {

    public static testmethod void ADRNonApprovalObjectUpdateChildRecordwithSubmit()
    { 
       
       
        //buidling the ADR Master Object   
User u =[select id from user where Username = 'bryan.revelant@delmonte.com.saa'];
          ADR__c newadr = new ADR__c();

        newadr.Review__c ='test account';
        newadr.Affiliate_Company__c = 'Test';
        newadr.Apex_Status__c = 'Testing Vendor';
        newadr.Next_Step__c = '';    

        newadr.OwnerId = u.id;
   
           insert newadr;
          
          
         ADR__Share newadrshare3 = new ADR__Share();
       
        newadrshare3.ParentId = newadr.id;
        newadrshare3.AccessLevel = 'Edit';
        newadrshare3.UserOrGroupId = newadr.OwnerId;      
       // newadrshare.UserOrGroupId = NEWADRVOU.User__c;
   
      //  insert newadrshare3; 

           //Building the attachement


      ADR_Non_Approval_Object__c NEWADRNONAO = new ADR_Non_Approval_Object__c();
     //User u =[select id from user where isActive=true limit 1];    
         
        NEWADRNONAO.ADR__c = newadr.id;
        NEWADRNONAO.User__c = u.id;
        NEWADRNONAO.Approval__c = ''; 
        NEWADRNONAO.Approval_Status_Date_Time__c = 'Testing Vendor';
        NEWADRNONAO.CheckReadAccess__c = true;
        NEWADRNONAO.Comments__c = 'Testing cat';
       
        insert NEWADRNONAO;
       
           
     ADR_VIew_Only_Users__c NEWADRVOU = new ADR_VIew_Only_Users__c();
         User ua =[select id from user where isActive=true limit 1];
          NEWADRVOU.User__c = ua.id;
         NEWADRVOU.ADR__c = newadr.id;
        NEWADRVOU.Status__c = '';
      
         insert NEWADRVOU;
       
    newadr.Next_Step__c = 'Submit';
     NEWADRNONAO.Approval__c = 'Submit';
    NEWADRVOU.Status__c = 'Submit';
      try {
            update newadr;
            update NEWADRVOU;
            update NEWADRNONAO;
        } catch (DMLException ex) {
            System.assert(true, 'Please Attach The Required Document Below In Notes and Attachment Section.');
        }
   

         ADR__Share newadrshare1 = new ADR__Share();
       
        newadrshare1.ParentId = NEWADRNONAO.ADR__c;
        newadrshare1.AccessLevel = 'Edit';
        //newadrshare.UserOrGroupId = u.id;      
        newadrshare1.UserOrGroupId = NEWADRVOU.User__c;
       
       
       
      insert newadrshare1;
  
             list<ADR__Share> Results = new list<ADR__Share>
        ([SELECT ParentId, AccessLevel, UserOrGroupId FROM ADR__Share]);
system.assert(Results.size()>0, 'No Answes found: '+ Results);
         } 
    }
Hello, 

If the user is assigned to a 1 record type but there are two on the object how can you program this on save?

I have a Visualforce page that saves records. Upon save the record type is null. I controll record types with visibility. I have done some research however I am comming up a bit short. The permission sets sets the record type. The below methods states that the current users does not require access :( I want to set the record type on save to whatever the permssion set says they have. 

getRecordTypeInfos()
Returns a list of the record types supported by this object. The current user is not required to have access to a record type to see it in this list.
getRecordTypeInfosById()
Returns a map that matches record IDs to their associated record types. The current user is not required to have access to a record type to see it in this map.
getRecordTypeInfosByName()
Returns a map that matches record labels to their associated record type. The current user is not required to have access to a record type to see it in this map.
I want a validation on the Javascript buttin, where if the current user is not the owner of the record, then display an error message. Is this possible. It doesnt seem to like userid.

I have tried var currentUser = sforce.connection.getUserInfo().userId
$userid
etc.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

  var currentUser = sforce.connection.getUserInfo().userId

// identify the record
var o = new sforce.SObject("ADR_Non_Approval_Object__c");

o.id = "{!ADR_Non_Approval_Object__c.Id}";

if(currentUser.id != o.OwnerId){
alert("You must be the Assigned Approver to Approve this request.");
}
else{



// make the field change
o.Approval__c = "Approve";
o.Approval_Status_Date_Time__c = new Date();

// save the change
sforce.connection.update([o]);
}
//refresh the page
window.location.reload();
Hello, 

I think maybe I have a design question. High level I have a Master Child relation ship. On the child object I have 2 custom Javascript buttons, however you can not hide these from view without JQuery. So I thought that could be done through Visualforce. After the users enter in data for the master object, they then have to add data to the child object before they are done. 

After they enter in information in the child, and click save. When users enter into the saved child object I want two buttons two appear or not appear pening on a field. I am not sure how to design. If I create a VF for a child How do I add that to my master object like standard Salesforce? Do I have to create a VF for the Master then too? Do I have to add this as a button on the master. 

I only have one tab which is the master object. So its like I want a button on Contacts but not Accounts. If you enter data for account then the user enter data in the Contact once saved and re entery into Contact I want two buttons two appear based on a field. I am not sure how to approach this. 

 contact



Once the User click the Highlighted contact I want the standard look and feel of Salesforce, just so I can hide some javascript buttons. Please let me knof if you have any questions



Hello,

I have a cross object that looks up to a user and a parent. I have put a trigger on the parent, trying to give sharing access to all users that are on the child object user lookup.

I am getting the below error message:

Apex trigger ADRSharringTrigger caused an unexpected exception, contact your administrator: ADRSharringTrigger: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ACCESS_LEVEL, : []: Trigger.ADRSharringTrigger: line 29, column 1

trigger ADRSharringTrigger on ADR__c (after update) {

      List<ADR__Share> ADR_Shares = new List<ADR__Share>();

   
    list<id> ADRSubmittedList = new list<id>();
    list<ADRUser__c> ADRUserList = new list<ADRUser__c>();
   
    for(ADR__c lstADRTrigger : trigger.new){
        if(lstADRTrigger.Next_Step__c == 'Submit'){
            ADRSubmittedList.add(lstADRTrigger.id);
        }

    for(ADRUser__c lstADRUser : [Select ID, Status__c, ADR__c, User__c from ADRUser__c where ADR__c in :ADRSubmittedList] ){
    
     ADR__Share  ADR_share = new ADR__Share();
    ADR_share.ParentId = lstADRUser.ADR__c;
    ADR_share.AccessLevel = 'All';
     ADR_share.UserOrGroupId = lstADRUser.User__c;

    
      SCD_Shares.add(scd_share);
    
    
     insert SCD_Shares;
    
    
   
    }
}
I have the below trigger, to update a child if a field on the parent is a specific value. 

I am getting the below error

Error: Compile Error: Invalid field Status__c for SObject ADR__c at line 28 column 1


trigger ADRParentUpdateChild on ADR__c ( after update, after insert) {

List<ADR__c > ParentRecords= [Select id, Next_Step__c, (Select ADR__c, Status__c FROM ADRUser__r) from ADR__c  WHERE id IN :Trigger.newMap.keySet()];

for(ADR__c parent: ParentRecords){
if(parent.Next_Step__c == 'Submit'){
   
parent.Status__c = 'Submit';
   }
   }
   
}
Hello, 

Was hoping for a bit of help with the below parent child trigger

Parent is ADR
CHILD is ADRUser

The below trigger works but, I want add some additional logic. If parent record Next_Step__c = submit then update the child ADRUser__c = Submit else do nothing. 

My SOQL is on the child record and my trigger on the parent. 

Help on the below?



trigger ADRParentUpdateChild on ADR__c ( after update, after insert) {
List<ADRUser__c > childRecords = [Select ADR__c, Status__c FROM ADRUser__c WHERE ADR__c IN :Trigger.newMap.keySet()];
        for(ADRUser__c child :childRecords){
            if(child.Status__c == null){
                child.Status__c = 'Submit';
            }
        if(childRecords.size() > 0)
            update childRecords;
}
I have an apex trigger on a formula field. The formula field is coming from a parent object if that makes a difference. 

Order of operations
users enter stuff on parent hits save. 
User enters data on child hit save. 
User then goes back to parent - hits a drop down selects submit
This provides the data in the formula field 
I have a trigger if condition on the child formula field that says the below. 
The problem I have found is it does do the logic I am stating unless the user edits the record and clicks save, or already has the parent value set to submit. What I want is as soon as the user enter the submit button the trigger fire on the child object. Please advise if you can 

trigger ADRUserTrigger on ADRUser__c ( before update, before insert){     
     for (ADRUser__c a : Trigger.New) {
    if (a.Next_Step2__c == 'Submit') {
           
update some records 
       
}

Any help would be nice


Having an issue with the below test class. I have an insert trigger for the sharing object upon a field change. When the field next_step = submit then the code grabs a look up to user on the child, and gives the user visibility to the parent. 

I keep getting an error: 
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

Class.TestADRShareSubmitV2.ADRNonApprovalObjectUpdateChildRecordwithSubmit: line 136, column 1



@istest
public  class TestADRShareSubmitV2 {

    public static testmethod void ADRNonApprovalObjectUpdateChildRecordwithSubmit()
    { 
       
       
        //buidling the ADR Master Object   
User u =[select id from user where Username = 'bryan.revelant@delmonte.com.saa'];
          ADR__c newadr = new ADR__c();

        newadr.Review__c ='test account';
        newadr.Affiliate_Company__c = 'Test';
        newadr.Apex_Status__c = 'Testing Vendor';
        newadr.Next_Step__c = '';    

        newadr.OwnerId = u.id;
   
           insert newadr;
          
          
         ADR__Share newadrshare3 = new ADR__Share();
       
        newadrshare3.ParentId = newadr.id;
        newadrshare3.AccessLevel = 'Edit';
        newadrshare3.UserOrGroupId = newadr.OwnerId;      
       // newadrshare.UserOrGroupId = NEWADRVOU.User__c;
   
      //  insert newadrshare3; 

           //Building the attachement


      ADR_Non_Approval_Object__c NEWADRNONAO = new ADR_Non_Approval_Object__c();
     //User u =[select id from user where isActive=true limit 1];    
         
        NEWADRNONAO.ADR__c = newadr.id;
        NEWADRNONAO.User__c = u.id;
        NEWADRNONAO.Approval__c = ''; 
        NEWADRNONAO.Approval_Status_Date_Time__c = 'Testing Vendor';
        NEWADRNONAO.CheckReadAccess__c = true;
        NEWADRNONAO.Comments__c = 'Testing cat';
       
        insert NEWADRNONAO;
       
           
     ADR_VIew_Only_Users__c NEWADRVOU = new ADR_VIew_Only_Users__c();
         User ua =[select id from user where isActive=true limit 1];
          NEWADRVOU.User__c = ua.id;
         NEWADRVOU.ADR__c = newadr.id;
        NEWADRVOU.Status__c = '';
      
         insert NEWADRVOU;
       
    newadr.Next_Step__c = 'Submit';
     NEWADRNONAO.Approval__c = 'Submit';
    NEWADRVOU.Status__c = 'Submit';
      try {
            update newadr;
            update NEWADRVOU;
            update NEWADRNONAO;
        } catch (DMLException ex) {
            System.assert(true, 'Please Attach The Required Document Below In Notes and Attachment Section.');
        }
   

         ADR__Share newadrshare1 = new ADR__Share();
       
        newadrshare1.ParentId = NEWADRNONAO.ADR__c;
        newadrshare1.AccessLevel = 'Edit';
        //newadrshare.UserOrGroupId = u.id;      
        newadrshare1.UserOrGroupId = NEWADRVOU.User__c;
       
       
       
      insert newadrshare1;
  
             list<ADR__Share> Results = new list<ADR__Share>
        ([SELECT ParentId, AccessLevel, UserOrGroupId FROM ADR__Share]);
system.assert(Results.size()>0, 'No Answes found: '+ Results);
         } 
    }
Hello, 

If the user is assigned to a 1 record type but there are two on the object how can you program this on save?

I have a Visualforce page that saves records. Upon save the record type is null. I controll record types with visibility. I have done some research however I am comming up a bit short. The permission sets sets the record type. The below methods states that the current users does not require access :( I want to set the record type on save to whatever the permssion set says they have. 

getRecordTypeInfos()
Returns a list of the record types supported by this object. The current user is not required to have access to a record type to see it in this list.
getRecordTypeInfosById()
Returns a map that matches record IDs to their associated record types. The current user is not required to have access to a record type to see it in this map.
getRecordTypeInfosByName()
Returns a map that matches record labels to their associated record type. The current user is not required to have access to a record type to see it in this map.
I want a validation on the Javascript buttin, where if the current user is not the owner of the record, then display an error message. Is this possible. It doesnt seem to like userid.

I have tried var currentUser = sforce.connection.getUserInfo().userId
$userid
etc.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

  var currentUser = sforce.connection.getUserInfo().userId

// identify the record
var o = new sforce.SObject("ADR_Non_Approval_Object__c");

o.id = "{!ADR_Non_Approval_Object__c.Id}";

if(currentUser.id != o.OwnerId){
alert("You must be the Assigned Approver to Approve this request.");
}
else{



// make the field change
o.Approval__c = "Approve";
o.Approval_Status_Date_Time__c = new Date();

// save the change
sforce.connection.update([o]);
}
//refresh the page
window.location.reload();



Hello,

I have a cross object that looks up to a user and a parent. I have put a trigger on the parent, trying to give sharing access to all users that are on the child object user lookup.

I am getting the below error message:

Apex trigger ADRSharringTrigger caused an unexpected exception, contact your administrator: ADRSharringTrigger: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ACCESS_LEVEL, : []: Trigger.ADRSharringTrigger: line 29, column 1

trigger ADRSharringTrigger on ADR__c (after update) {

      List<ADR__Share> ADR_Shares = new List<ADR__Share>();

   
    list<id> ADRSubmittedList = new list<id>();
    list<ADRUser__c> ADRUserList = new list<ADRUser__c>();
   
    for(ADR__c lstADRTrigger : trigger.new){
        if(lstADRTrigger.Next_Step__c == 'Submit'){
            ADRSubmittedList.add(lstADRTrigger.id);
        }

    for(ADRUser__c lstADRUser : [Select ID, Status__c, ADR__c, User__c from ADRUser__c where ADR__c in :ADRSubmittedList] ){
    
     ADR__Share  ADR_share = new ADR__Share();
    ADR_share.ParentId = lstADRUser.ADR__c;
    ADR_share.AccessLevel = 'All';
     ADR_share.UserOrGroupId = lstADRUser.User__c;

    
      SCD_Shares.add(scd_share);
    
    
     insert SCD_Shares;
    
    
   
    }
}
I have the below trigger, to update a child if a field on the parent is a specific value. 

I am getting the below error

Error: Compile Error: Invalid field Status__c for SObject ADR__c at line 28 column 1


trigger ADRParentUpdateChild on ADR__c ( after update, after insert) {

List<ADR__c > ParentRecords= [Select id, Next_Step__c, (Select ADR__c, Status__c FROM ADRUser__r) from ADR__c  WHERE id IN :Trigger.newMap.keySet()];

for(ADR__c parent: ParentRecords){
if(parent.Next_Step__c == 'Submit'){
   
parent.Status__c = 'Submit';
   }
   }
   
}
Hello, 

Was hoping for a bit of help with the below parent child trigger

Parent is ADR
CHILD is ADRUser

The below trigger works but, I want add some additional logic. If parent record Next_Step__c = submit then update the child ADRUser__c = Submit else do nothing. 

My SOQL is on the child record and my trigger on the parent. 

Help on the below?



trigger ADRParentUpdateChild on ADR__c ( after update, after insert) {
List<ADRUser__c > childRecords = [Select ADR__c, Status__c FROM ADRUser__c WHERE ADR__c IN :Trigger.newMap.keySet()];
        for(ADRUser__c child :childRecords){
            if(child.Status__c == null){
                child.Status__c = 'Submit';
            }
        if(childRecords.size() > 0)
            update childRecords;
}
I have an apex trigger on a formula field. The formula field is coming from a parent object if that makes a difference. 

Order of operations
users enter stuff on parent hits save. 
User enters data on child hit save. 
User then goes back to parent - hits a drop down selects submit
This provides the data in the formula field 
I have a trigger if condition on the child formula field that says the below. 
The problem I have found is it does do the logic I am stating unless the user edits the record and clicks save, or already has the parent value set to submit. What I want is as soon as the user enter the submit button the trigger fire on the child object. Please advise if you can 

trigger ADRUserTrigger on ADRUser__c ( before update, before insert){     
     for (ADRUser__c a : Trigger.New) {
    if (a.Next_Step2__c == 'Submit') {
           
update some records 
       
}

Any help would be nice