You need to sign in to do that
Don't have an account?
test vijay
How to create AccountShare in apex Testclass
hy Guys,
I want to Create AccountSahre WHERE RowCause='Territory' such as I created AccountShare object I got this error : Error message: field integrity exception: RowCause (cannot insert sharing row with this cause).
following is piece of code of my apex class and I am sure if i got accountShare object in test class then my requirment will be fulfuill.
Thanks In Advance
I want to Create AccountSahre WHERE RowCause='Territory' such as I created AccountShare object I got this error : Error message: field integrity exception: RowCause (cannot insert sharing row with this cause).
following is piece of code of my apex class and I am sure if i got accountShare object in test class then my requirment will be fulfuill.
Map<Id,account> accountMap = new Map<Id,account>(); set<Id> setAccShareIds = new set<Id>(); for (Account a : [SELECT Id,Name, (SELECT UserOrGroupId from Shares WHERE RowCause='Territory') FROM Account WHERE Id IN :accountIds]) { accountMap.put(a.Id,a); if(!a.Shares.isEmpty()) { for(AccountShare s : a.Shares) { setAccShareIds.add(s.UserOrGroupId); } } }I have tried many way but not successed. can anybody know me how to resolve this issue.
Thanks In Advance
I have faced this error Error message: field integrity exception: RowCause (cannot insert sharing row with this cause).
I think when you was trying to create accountShare object in testClass at that time you got this error but I think you don't need to create accountShare object in test class.
follow follwoing steps to create accountShare and any share object in apex.
if you want accountShare object and any share object with RowCause 'Territory' in your apexTest class then you must follow following steps.
1. In your org, search Territory in the quick find box and select Territory Models.
2. click View Rules which state is "active".
Note - if you not found Territory Models then you have to follow following referance url.
How to enabled Territory for salesforce.
Follow - https://trailhead.salesforce.com/content/learn/modules/territory-management-basics
3. open any rule.
4. In Rule Criteria Section check at which filed rule is apply.
For instance : Account: Industry EQUALS Apparel
above rule means you will have to set account industry with Apparel value in your test class while inserting Account Object.
you will have to set that value in test class account field.
get reference from following Class. Remember that your rules alwas asign with Territory and if multi rules are assigned and active, you must add all active condition.
In my org, Rule Criteria
1. Account: IndustryEQUALSTechnology
2. Account: TypeEQUALSProspect
both rules are active.
let me know if it helps you and marking it as best answer so that it can help to others in future.
Thank You
All Answers
I have faced this error Error message: field integrity exception: RowCause (cannot insert sharing row with this cause).
I think when you was trying to create accountShare object in testClass at that time you got this error but I think you don't need to create accountShare object in test class.
follow follwoing steps to create accountShare and any share object in apex.
if you want accountShare object and any share object with RowCause 'Territory' in your apexTest class then you must follow following steps.
1. In your org, search Territory in the quick find box and select Territory Models.
2. click View Rules which state is "active".
Note - if you not found Territory Models then you have to follow following referance url.
How to enabled Territory for salesforce.
Follow - https://trailhead.salesforce.com/content/learn/modules/territory-management-basics
3. open any rule.
4. In Rule Criteria Section check at which filed rule is apply.
For instance : Account: Industry EQUALS Apparel
above rule means you will have to set account industry with Apparel value in your test class while inserting Account Object.
you will have to set that value in test class account field.
get reference from following Class. Remember that your rules alwas asign with Territory and if multi rules are assigned and active, you must add all active condition.
In my org, Rule Criteria
1. Account: IndustryEQUALSTechnology
2. Account: TypeEQUALSProspect
both rules are active.
let me know if it helps you and marking it as best answer so that it can help to others in future.
Thank You
Thanks, it's working.