function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alejandro Gonzalez 18Alejandro Gonzalez 18 

Why is this method signature is not recognized?

I am creating an utility class for lists and sets. A centralized static place where i can Where clauses and select, similar to linq

verything works with Lists, But when i try this following signature.
class AddUserListUtility{
 public static Set<SObject> WherePropertyEqualsSet(Set<SObject> source, string propertyName, object value)
{
...
}
}


-- now the calling part. -- 
for(string rile : record.Roles__c.split(';'))
{
object converted = rile;
AddUserListUtility.WherePropertyEqualsSet(AllRoles, 'Role__c', converted);

}

That fails with the compile error
Method does not exist or incorrect signature: void WherePropertyEqualsSet(Set<RoleToAdd__c>, String, Object) from the type AddUserListUtility

Im baffled as the signatures seem to match.
Btw using List types work.

 
Velvel Marasow 10Velvel Marasow 10
Is "AllRoles" a Set? Might you be mixing SObjects and Objects?
Asif Ali MAsif Ali M
May I know your excat need for using third param as Object Type? 
Alejandro Gonzalez 18Alejandro Gonzalez 18
The reason fo rusing Object is so i can keep it generic. The idea is so I can say from this Set get all obejct, where the column (second paramater) equals value(third parameter)

 
Alejandro Gonzalez 18Alejandro Gonzalez 18
AllRoles is a set<SObject> it is a custom list, with the name Set<Roles__c> AllRoles
Velvel Marasow 10Velvel Marasow 10
From the error, it seems that the Set is of type <RoleToAdd__c>, not <Role__c>
Asif Ali MAsif Ali M
Hi Alejandro,

To kepp it generic use SObject not Object . Object is a System object not used to store any TYPE value into it. Here is the code I see for Object class. 
// Generated by Illuminated Cloud on Wed Apr 12 17:21:52 EDT 2017. Do not edit.

global class /*System.*/Object 
{
    global Boolean equals(Object obj)
    {
    }

    global Integer hashCode()
    {
    }
}


If you are checking 2nd and 3rd params are equal or not then you should change your Method signature to the below.
 
public static Set<SObject> WherePropertyEqualsSet(Set<SObject> source, string propertyName, String value)
And your for loop should be like below.
for(string rile : record.Roles__c.split(';'))
{

    AddUserListUtility.WherePropertyEqualsSet(AllRoles, 'Role__c', rile);

}



 
Alejandro Gonzalez 18Alejandro Gonzalez 18
the following signature works 
public static List<SObject> WherePropertyEquals(List<SObject> source, string propertyName, object value)

notice the only change was using  a List vs a set.

Also using object as a parameter is the way to make them generic. All primitive datatype  inherit from the Object class. Using Object is the way of using it generic. Also forcing it to be an SObject will not let me use columns that are Integers or boolean, which is the point of this.
Asif Ali MAsif Ali M
Interesting to know about Object type. I will start using it.