Microsoft graph api returning NULL in Department field - azure-active-directory

I have given all required permissions for retrieving user info from Azure active directory like User.Read.All and User.Read but still getting Department and EmployeeId field as NULL
code used:
public Microsoft.Graph.User GetUser(ref GraphServiceClient graphServiceClient, string UserId)
{
return graphServiceClient.Users[UserId].Request().GetAsync().Result;
}

According to the documentation both department and employeeId are returned only on $select.
Use Select method and specify those two properties. If you need to return more properties, they need to be specified in Select. Without using Select, Graph API return only default set of properties.
public Microsoft.Graph.User GetUser(ref GraphServiceClient graphServiceClient, string UserId)
{
return graphServiceClient.Users[UserId]
.Request()
.Select("department,employeeId")
.GetAsync()
.Result;
}
Resources:
Select parameter

Related

How do I get info from lookup in salesforce query

I have a custom salesforce object Installation__c and it has a custom field Product__c which is a lookup to a custom object Product__c I am trying to get the fields from the child object using these query:
public with sharing class InstallationController {
#AuraEnabled
public static List<Installation__c> getItems() {
// Perform isAccessible() checking first, then
return [SELECT Id, Name, Installation_Display_Name__c, Product__c, Status__c, (SELECT Product__c.Name FROM Product__c) FROM Installation__c];
}
}
I get the error:
Didn't understand relationship 'Product__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
I have tried changing the Query to
FROM Product__rand FROM Product__c__r but neither seems to work, how do I fix my query?
If you're traversing up or down a relationship hierarchy, the __c suffix becomes __r (r for 'relationship') until you finally get to the field that you're looking for (which still ends in __c if it's a custom field). So in your case, it will be
public with sharing class InstallationController {
#AuraEnabled
public static List<Installation__c> getItems() {
// Perform isAccessible() checking first, then
return [SELECT Id, Name, Installation_Display_Name__c, Product__r.Name, Status__c FROM Installation__c];
}
}
So, the change here is, for the relationship you have to use Product__r.Name
Click into the relationship on the object that has the look up. Copy the relationship name adding __r to it
This example would be Test_Drives__r

I to assign a default account to a custom object using Visualforce page

I am new to salesforce development. I am trying to create a visualforce page which helps to insert a new record into the custom object. Custom object has master-detail relationship with account. I am having issue when assiging a default value to the Account. The account already exists in the accounts table. Here is the Apex class I am trying.
public class RelatedAccount{
public Account parent {get; set;}
public RelatedAccount(ApexPages.StandardController controller){
Transaction__c child = (Transaction__c)controller.getRecord();
if (child.Account__c != null) { parent = [Select ID,Name FROM Account WHERE Account.Name = :'1Company Inc.,' LIMIT 1];
child.Account__c = parent;
}
}}
I am getting the error : "Illegal assignment from Account to Id"
Thanks In advance.
This should work:
child.Account__c = parent.Id
In your case you try to put the "whole" account object object into the Lookup field. But this just needs the Id of the parent account.

Unable to filter using ContentDocument id in query in trigger query not retrieving any results

I have a requirement to make to make a file private and be available to only the user whose role name consists the name of the file for a specific custom object. For this I am trying to retrieve from Content Document Link with the custom object name LinkedEntity.Type and ContentDocumentid as filters, when I hard code the ContentDocumentid it is working fine but when I try to dynamically provide the ContentDocumentId then the query is not returning any result. I am adding a snippet of my code. Please Help!!. Thanks
List<Id> listOfConDocuId = new List<Id>();
for(ContentVersion cv: Trigger.new){
if((!cv.Title.contains('product proposal')) || (!cv.Title.contains('final')) || (!cv.Title.contains('packet')))
listOfConDocuId.add(cv.ContentDocumentId);
}
Map<Id, Project__c> mapOfProjectId = new Map<Id, Project__c>([SELECT Id FROM Project__c]);
Set<Id> setOfProjectId = mapOfProjectId.keySet();
List<ContentDocumentLink> LinkedProject = [SELECT ContentDocumentId, LinkedEntityId, ContentDocument.Title FROM ContentDocumentLink where LinkedEntityId in :setOfProjectId and LinkedEntity.Type='Project__c' and ContentDocumentId IN :listOfConDocuId];`
I don't think it's necessary to add a WHERE clause for both ID and TYPE. Id should be enough. As far as restricting files to only users with certain roles, have you tried sharing the Custom Object (Project__c) with only those users and then simply linking the files to that Custom Object record with Inferred Permission?
Read more about the sharing types and visibility of Content Document Link here:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocumentlink.htm

Not able to insert AccountPartner through test class in salesforce

I was not able to insert mock data for AccountPartner through test class. I tried by inserting 2 accounts and one Partner object. Actually same code is working in case of running from Apex class or executing from developer console. Please see the below code and output and let me know solution..
#isTest
private class TestAccountPartner {
private static testmethod void unittest(){
test.startTest();
Account sourceAccount = new Account();
Account targetAccount = new Account();
sourceAccount.AccountNumber='Number1';
sourceAccount.Name='name1';
targetAccount.AccountNumber='Number2';
targetAccount.Name='name2';
insert sourceAccount;
insert targetAccount;
Partner p = new Partner(AccountFromId=sourceAccount.ID, AccountToId=targetAccount.ID);
insert p;
Account sa = [select ID from Account where Name='name1'];
Account ta = [select ID from Account where Name='name2'];
System.debug('Source Account is: '+sa);
System.debug('Target Account is: '+ta);
List<Partner> partners = [select AccountFromId from partner];
System.debug('Partner objects are: '+partners);
List<AccountPartner> accountPartners = [select AccountFromId from AccountPartner];
System.debug('account partners are: '+accountPartners);
test.stopTest();
}
}
Output is:
07:24:48:174 USER_DEBUG [26]|DEBUG|Source Account is: Account:{Id=00128000007YZk7AAG}
07:24:48:174 USER_DEBUG [27]|DEBUG|Target Account is: Account:{Id=00128000007YZk8AAG}
07:24:48:176 USER_DEBUG [30]|DEBUG|Partner objects are: (Partner:{AccountFromId=00128000007YZk7AAG, Id=00I28000000ZeBTEA0})
07:24:48:177 USER_DEBUG [33]|DEBUG|account partners are: ()
It's been a while but I think this is because account partner is one of the special Role type relationships. Have you tried accessing the Target account's AccountPartner collection and using the add() method to add the Source account.
This isn't identical to your situation, but the solution has a similar example that is adding partners:
https://salesforce.stackexchange.com/questions/3805/how-to-update-account-object-when-related-accountpartner-is-updated-inserted-del

Relationships Inside Laravel

I'm trying to find out how to work with the following relationship. I have a users table with a few fields like id, username, name, role_id. I have a roles table that has an id, and name field.
All users have one role and roles belong to all users so that more than one user can have the same role obviously. I have the following in the corresponding models.
I'm trying to figure out what I need to do so that when I do a call for all users it will get the name of the role and show it instead of the role_id.
class Role extends Eloquent {
public function users()
{
return $this->hasMany('User'); // this will get all the users that have a role_id that matches it's own id
}
}
class User extends Eloquent implements UserInterface, RemindableInterface {
public function role()
{
return $this->belongsTo('Role'); // this will select the role by 'role_id' and return an instance
}
}
Any other ideas?
You can use eager loading, To get the name of the role you just call the function you defined in user model.
$user->role->name;
see Laravel docs for more Information.

Resources