• MitchF
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hello,

 

We are looking for someone to take on several initiatives we have at our company, architect the solutions and bring home the projects.

 

We have a strong preference for someone who can spend time in our office just south of Denver working with users to insure the solution is developed in the best way.

 

Looking forward to hearing from the respondants!

 

  • October 22, 2012
  • Like
  • 0

Hello,

This is my first post, but I want to thank all the contributors for the countless times I have found something useful here.  Here is the issue I am experiencing:

I am using a trigger to create two manual sharing rules in the OpportunityShares object by adding the necessary properties to list elements. The list is of sObject type OpportunityShares and called newOppShrs.   First I set the properties for one, then add it to the list, then I resue the same OpportunityShares sObject (called partnerShare) and add it to the list.  Although I am adding two separate records to the sObject list, I'm receiving an error regarding adding duplicate records into the OpportunityShares table.  Additionally, debug logs show me that both elements in my list are identical (the second element is what is attempting to be written to the OppShares table), confirming that I'm not doing something right when adding these elements.  I've confirmed that at the time I'm adding the elements to my list the values are unique for UserOrGroupId.  Here is the (partial) code that is causing the error.

 

 

//Access the Contact/User Map using the Allocator's
//contact Id from Allocator__c to get the
//value of the corresponding user's ID and add the
//property to the partnerShare object and add the record
//to to the newOppShares list of OpportunityShare records

if (o.Allocator__c != null){
	system.debug('Alloc Shr Add ' + contactToUserMap.get(o.Allocator__c));
	partnerShare.UserOrGroupId = contactToUserMap.get(o.Allocator__c);
	partnerShare.OpportunityAccessLevel = 'Edit';
	newOppShrs.add(partnerShare);
	system.debug('partnershare Alloc = ' + partnerShare.UserOrGroupId +
	 ' ' + partnerShare.OpportunityAccessLevel);			
}
					
					
//Do it again for the Underwriter
if (o.Underwriter__c != null){
	system.debug('Underw Shr Add ' + contactToUserMap.get(o.Underwriter__c));
	partnerShare.UserOrGroupId = contactToUserMap.get(o.Underwriter__c);
	partnerShare.OpportunityAccessLevel = 'Edit';
	newOppShrs.add(partnerShare);
	system.debug('partnershare Alloc = ' + partnerShare.UserOrGroupId + 
	' ' + partnerShare.OpportunityAccessLevel);
}

//Add'l Debug
for(OpportunityShare os : newOppShrs){
	system.debug('OpportunityId = ' + os.OpportunityId + ' ' + 'UserOrGroupId = ' + os.UserOrGroupId);}

//Perform the DML operation, adding both records
	try{		
		insert newOppShrs;
	}
	catch (DMLException DMLe){
		system.assert(true,'Caught DML Exception: '+DMle.getDMLMessage(0));
        	system.debug('\n\nCaught DML Exception: '+DMle.getDMLMessage(0));
	}

 

 

FYI, I can make this work by re-instantiating the partnerShare sObject between adding the allocator and underwriter elements by adding the following:

 

 

partnerShare = new OpportunityShare();
partnerShare.OpportunityId = o.Id; //I also do this before the first code snippet)

 

 What I can't understand is why I have to do that.  Shouldn't I be able to reuse it?

Thanks in advance,

Mitch