You need to sign in to do that
Don't have an account?
Kunlun
How can I get available recordtype by account information with .net web api
| I think it maybe use discribe method to get it. But I didn't find it. I have to select account record type before I create account. Different users login should get different record type. I want to do the create functionality on a web page with .net web api. How can I get the available account record types by login user with web api? |
I'm feeling nice today.. Hope you find this code helpful!!
/// <summary>
/// Return the system user role.. I.E. the workflow type
/// </summary>
/// <param name="CRMManager"></param>
/// <param name="systemUserId"></param>
/// <returns></returns>
public string CRMUserGetRole(string userId)
{
string userRole = "";
string userRoleId = "";
// Create Query string to get roleid
string qs = "SELECT UserRoleId from User WHERE Id = '" + userId + "'";
CRMSDK.QueryResult userQuery = this.CRMService.query(qs);
// Get the records
CRMSDK.sObject[] records = userQuery.records;
// Get the results
for (int i = 0; i < records.Length; i++)
{
CRMSDK.User tempUser = (CRMSDK.User)records[i];
userRoleId = tempUser.UserRoleId;
}
qs = "SELECT Name FROM UserRole Where Id = '" + userRoleId + "'";
CRMSDK.QueryResult roleQuery = this.CRMService.query(qs);
// get the records
CRMSDK.sObject[] roles = roleQuery.records;
for (int i = 0; i < records.Length; i++)
{
CRMSDK.UserRole tempRole = (CRMSDK.UserRole)roles[i];
userRole = tempRole.Name;
}
return userRole;
}
/// <summary>
/// Given a role and entity type will return the corresponding record type id
/// </summary>
/// <param name="personRole">the role of the current entity</param>
/// <param name="entityType">the entity type we wish to retreive record type for</param>
/// <returns>the entity recordtypeId</returns>
public string CRMEntityGetRecordTypeId(string entityRole, string entityType)
{
string recordTypeId = null;
// create the query
string queryString = "SELECT Id FROM RecordType WHERE Name = '" + entityRole + "' ";
queryString = queryString + " AND sObjectType = '" + entityType + "' ";
// create the result set
CRMSDK.QueryResult myResults = this.CRMService.query(queryString);
if (myResults.size > 0)
{
CRMSDK.RecordType currentRecordType = ((CRMSDK.RecordType)myResults.records[0]);
recordTypeId = currentRecordType.Id;
}
return recordTypeId;
}