You need to sign in to do that
Don't have an account?
![Staci Staci](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Entitlements and Portal Users
I know Entitlements can be added to cases logged by community users automatically with code, but what about Portal users? We are still using the portal but want to use entitlements. Portal users are the main users that log cases. Is this doable with the same code?
trigger CW_defaultEntitlement on Case (Before Insert, Before Update) { Set<Id> acctIds = new Set<Id>(); for(Case c : Trigger.new) { acctIds.add(c.AccountId); } List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId From Entitlement e Where e.AccountId in :acctIds and e.EndDate >=Today and e.StartDate <= Today]; if(entls.isEmpty()==false){ for(Case c : Trigger.New) { if(c.EntitlementId == null && c.AccountId != null){ for(Entitlement e:entls){ if(e.AccountId== c.AccountId){ c.EntitlementId = e.Id; } } } } } }
Cases should behave the same despite where they are created so that code should work. Anyway you could try doing this with process builder also. The only special thing you'd need to do is creating a hierarchy custom setting to store the entitlement Id so that you can reference it from your process.
Let me know if I can help you further :)
Regards
I'd rather just stick to the code. I'm on a time crunch and I was hoping the code SF provided in the admin guide was working but its not. I've tried this code now, which still only half works. It goes through and it finds the correct account in the first system debug, but never hits the second debug and says Rows: 0 when it gets to the List<Entitlement> in the logs. Any ideas?
Give it a try and tell me your progress :)
Regards
Yes I have the related list on the account