You need to sign in to do that
Don't have an account?
lodoss118
Trying to get the userRold id from the account owner relationship?
Hi i am having problems in getting the account owner user role id, i was trying to do this but it is wrong from the relationship query?
Didn't understand relationship 'User__r' in FROM part of query call
:'(
public static void Find_User(Account[] b)
{
try {
for(Account a : [select Id, PostCode_Area__c, (select Id, Name, UserRoleId,
Working_Area__c from User where Id = :b.OwnerId)
from Account where Id = :b.Id]) {
}
}
}
Didn't understand relationship 'User__r' in FROM part of query call
:'(
public static void Find_User(Account[] b)
{
try {
for(Account a : [select Id, PostCode_Area__c, (select Id, Name, UserRoleId,
Working_Area__c from User where Id = :b.OwnerId)
from Account where Id = :b.Id]) {
}
}
}
The SOQL-R part of the API docs covers it pretty well
http://www.salesforce.com/us/developer/docs/api/index_CSH.htm#sforce_api_calls_soql_relationships.htm
in my class ihave this method that checks the owner role id: -
public static Boolean isValidRole(Id ownerId) {
if(ownerId != null) {
User o = [select Id, UserRoleId from User where Id = :ownerId];
Id id = o.UserRoleId;
if(id == '123132123' || id == '12313321' || id == '12313123123321' || id == '123132132'
|| id == '12313123' || id == '12313123132' || id == '123131331' || id == '123123312'
|| id == '1231312321' || id == '1231332131')
{
return false;
}
}
return true;
}
Called in Find user method :-
public static void Find_User(Account[] b)
{
try {
for(Account a : b) {
if(isValidRole(a.OwnerId) != true)break;
String postCode = null;
String areaCode = null;
}
}
}
the trigger is called in account before insert, before update i.e.
Find_User(trigger.new);
Set ownerIds = new Set;
for(Account a : Trigger.new)
ownerIds.add(a.ownerId);
Map owners = [select, id, userRoleId from user where id in :ownerIds];
// now do stuff with the Trigger.new array, using the owners Map, to get the userRoleId of the account owner.
owner.userRoleId is always null?