You need to sign in to do that
Don't have an account?
fadwa mangoug
how to get the id of an object using its name ? ( object referenced by a lookup)
Hey there !
I'm having trouble with a method and can use some help plz !
So here's what I'm trying to do :
My method should give me the ID of an object when i use its name, for now i have this but it's not working, I have an error : " Method does not exist or incorrect signature: [Schema.DescribeSObjectResult].get()"
public integer TargetID() {
Schema.SObjectType sobjectType = Name.getSObjectType();
Integer sobjectId = sobjectType.getDescribe().get();
SObject record = Database.query('Select Id From ' + sobjectId + ' Where Name = :Name');
}
The problem is with the get(), I know it works with names but not with ID's.
Thanks in advance for the help :) !
I'm having trouble with a method and can use some help plz !
So here's what I'm trying to do :
My method should give me the ID of an object when i use its name, for now i have this but it's not working, I have an error : " Method does not exist or incorrect signature: [Schema.DescribeSObjectResult].get()"
public integer TargetID() {
Schema.SObjectType sobjectType = Name.getSObjectType();
Integer sobjectId = sobjectType.getDescribe().get();
SObject record = Database.query('Select Id From ' + sobjectId + ' Where Name = :Name');
}
The problem is with the get(), I know it works with names but not with ID's.
Thanks in advance for the help :) !
You cannot get the Id of the CustomObject using normal SOQL. You will have to use Tooling api to achieve this in salesforce. You can use below mentioned code:
Make sure your salesforce instance must be whitelisted in remote site settings in your org.