/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // Create a unique identifier for this sample for preventing name conflicts. var sampleIdentifier = Guid.NewGuid(); // Retrieve/create the system users to use for the sample. var ldapPath = String.Empty; _systemUserIds = SystemUserProvider.RetrieveDelegates( _serviceProxy, ref ldapPath); // Retrieve the root business unit to use for creating the team for the // sample. var businessUnitQuery = new QueryExpression { EntityName = BusinessUnit.EntityLogicalName, ColumnSet = new ColumnSet("businessunitid"), Criteria = new FilterExpression() }; businessUnitQuery.Criteria.AddCondition("parentbusinessunitid", ConditionOperator.Null); var businessUnitResult = _serviceProxy.RetrieveMultiple(businessUnitQuery); var businessUnit = businessUnitResult.Entities[0].ToEntity <BusinessUnit>(); // Get the GUID of the current user. var who = new WhoAmIRequest(); var whoResponse = (WhoAmIResponse)_serviceProxy.Execute(who); _currentUserId = whoResponse.UserId; // Create a team for use in the sample. var team = new Team { AdministratorId = new EntityReference( "systemuser", _currentUserId), Name = String.Format("User Access Sample Team {0}", sampleIdentifier), BusinessUnitId = businessUnit.ToEntityReference() }; _teamId = _serviceProxy.Create(team); // Add the second user to the newly created team. var addToTeamRequest = new AddMembersTeamRequest { TeamId = _teamId, MemberIds = new[] { _systemUserIds[1] } }; _serviceProxy.Execute(addToTeamRequest); // Create a lead for use in the sample. var lead = new Lead { CompanyName = "User Access Sample Company", FirstName = "Sample", LastName = "Lead", Subject = "User Access Sample Lead", }; _leadId = _serviceProxy.Create(lead); // Create a task to associate to the lead. var leadReference = new EntityReference(Lead.EntityLogicalName, _leadId); var task = new Task { Subject = "User Access Sample Task", RegardingObjectId = leadReference }; _taskId = _serviceProxy.Create(task); // Create a letter to associate to the lead. var letter = new Letter { Subject = "User Access Sample Letter", RegardingObjectId = leadReference }; _serviceProxy.Create(letter); }