• kivacailinanne
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Does it matter if you create duplicate Apex Sharing rows for the same Record and User?  When this is done, no errors are thrown and the duplicate share seems to succeed.

 

For example, if we take the provided example code, below, does it matter if this is executed many times?   Does it actually create duplicate rows? 

 

If it does create duplicate rows, can the duplication be stopped by changing the insert to an upsert? 

 

If that's not enough, how can one query to see if the share exists before re-creating it?

 

 // Create new sharing object for the custom object Job.
Job__Share jobShr = new Job__Share();

// Set the ID of record being shared.
jobShr.ParentId = recordId;

// Set the ID of user or group being granted access.
jobShr.UserOrGroupId = userOrGroupId;

// Set the access level.
jobShr.AccessLevel = 'Read';

// Set rowCause to 'manual' for manual sharing.
// This line can be omitted as 'manual' is the default value for sharing objects.
jobShr.RowCause = Schema.Job__Share.RowCause.Manual;

// Insert the sharing record and capture the save result.
// The false parameter allows for partial processing if multiple records passed
// into the operation.
Database.SaveResult sr = Database.insert(jobShr,false);

 

Hi,

 

I have created some batch apex code alongwith other triggers and class/controller codes. 

 

When I run individual test methods on them, I am able to get test success result alongwith nice code coverage %. However when I run all tests together, I get following test failure errors:-

 

1)System.AsyncException: Database.executeBatch cannot be called from a batch or future method.

2)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)

3)System.AsyncException: Future method cannot be called from a future method: getLead_Rollup_Amount(Id)

4)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)

 

Please note again that the exceptions dont come when tested individually.

 

Please advise on same.

 

 

Thanks,

 

Vimal