You need to sign in to do that
Don't have an account?
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST
Hi all! I am attempting to make an Apex trigger to share a record with a user when they are selected on a user search field entitled 'Assign to'. I have looked at every similarly-tagged post and none of them seem to have the answers I need...
I found this gem that I attempted to follow to the letter, but unfortunately am still receiving an error. Does anyone know what I'm doing wrong?
http://wiki.developerforce.com/page/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<SFDC_Support_Tickets__Share>
trigger Assign_To_Sharing on SFDC_Support_Tickets__c (after insert) {
if(trigger.isInsert){
List<SFDC_Support_Tickets__Share> ticketShares = new List<SFDC_Support_Tickets__Share>();
for(SFDC_Support_Tickets__c ticket : trigger.new){
SFDC_Support_Tickets__c assignToSharing = new SFDC_Support_Tickets__c();
ticketShares.ParentId = ticket.Id;
assignToSharing.UserOrGroupId = ticket.Assign_To__c;
assignToSharing.AccessLevel = 'edit';
assignToSharing.RowCause = Schema.SFDC_Support_Tickets__Share.RowCause.Assign_To_Sharing__c;
ticketShares.add(assignToSharing );
}
Database.SaveResult[] ticketShareInsertResult = Database.insert(ticketShares,false);
}
}
Jessi,
Change this in your code from
after insert
to
after update.
All Answers
ticketShares.ParentId = ticket.Id;
ticketShares is a list variable. I think you'll need to change this to
assignToSharing.ParentId = ticket.Id;
Thank you so much for your reply!
However, I'd had that assigned previously (I tried again just in case I'd misspelled it or something) and I got the following error:
trigger Assign_To_Sharing on SFDC_Support_Tickets__c (after insert) {
if(trigger.isInsert){
List<SFDC_Support_Tickets__Share> ticketShares = new List<SFDC_Support_Tickets__Share>();
for(SFDC_Support_Tickets__c ticket : trigger.new){
SFDC_Support_Tickets__c assignToSharing = new SFDC_Support_Tickets__c();
assignToSharing.ParentId = ticket.Id;
assignToSharing.UserOrGroupId = ticket.Assign_To__c;
assignToSharing.AccessLevel = 'edit';
assignToSharing.RowCause = Schema.SFDC_Support_Tickets__Share.RowCause.Assign_To_Sharing__c;
ticketShares.add(assignToSharing );
}
Database.SaveResult[] ticketShareInsertResult = Database.insert(ticketShares,false);
}
}
Jessi,
The error is self explanatory,this means you don't have any field called ParentId on SFDC_Support_Tickets__c object.
Also,your logic seems to be confusing as you are inserting the same object record and Trigger is also on the same object with same event,not sure what you want to achieve here.
Please let us know,we will certainly try to help you out.
I suppose I should have mentioned that I am brand new to Apex and am not 100% sure what I'm doing here :) Thank you so much for your quick replies so far!
Basically what I want is to automatically share a Support Ticket (SFDC_Support_Tickets__c) with a user when they are pulled up in the Assign to field (Assign_to__c). It sounded simple enough in the post, but clearly I'm having trouble!
I wasn't sure quite what your last post meant, Vinit, but the above is what I'm trying to achieve. Does that clear things up a little?
We just rewrote the thing and it passed the syntax check, but it's not doing anything. Here is the code we now have:
trigger SFDC_Support_Tickets_Share on SFDC_Support_Tickets__c (after insert) {
if(trigger.isInsert){
List<SFDC_Support_Tickets__Share> ticketShares = new List<SFDC_Support_Tickets__Share>();
for(SFDC_Support_Tickets__c ticket : trigger.new){
SFDC_Support_Tickets__Share assignToShare = new SFDC_Support_Tickets__Share();
assignToShare.ParentId = ticket.Id;
assignToShare.UserOrGroupId = ticket.Assign_to__c;
assignToShare.AccessLevel = 'edit';
assignToShare.RowCause = Schema.SFDC_Support_Tickets__Share.RowCause.Assign_To_Sharing__c;
ticketShares.add(assignToShare);
}
Database.SaveResult[] ticketShareInsertResult = Database.insert(ticketShares,false);
}
}
Jessi,
This logic/code looks good to me.You should be checking the debug logs and see if you have any share record being inserted or not.
Just put a system.debug() statement at the last and see whats coming in ticketShareInsertResult.
Well, the good news is I just learned to debug!
The bad news is, nothing relating to this trigger is showing up in the log. All of my workflows are showing up, which is super awesome, but it looks like the trigger is literally doing nothing.
Thank you so much for your help so far, Vinit. Do you have any other thoughts or suggestions? I can post the debug dump here if you'd really like!
Jessi,
Your Trigger is on insert event,so it would only fire if you insert any SFDC_Support_Tickets__c record.
Are you iserting a record or updating it.If you want ,I can have a look on debug logs,post it here..
Oh my gosh you're right, and that's the opposite of what we need!
What we need to happen is that, after a record is already created, when the Assign_to__c field is updated, the trigger fires. Where do we change the code to make that happen?
Also, thank you so much for all of your help on this! I can't tell you how important it's been.
Jessi,
Change this in your code from
after insert
to
after update.
I just danced around the office like a crazy person! It worked!! Thank you so much for all of your help, you are amazing!
Jessi,
Happy to help!!