1

I'm having a class with a picklistfield (field1) and in that I'm getting values as

string field1;
Public string getfield1(){return field1;}
public void setTemplate(string field1){this.field1 = field1;}
       public list<selectoption> gettempname()
      {
          list<selectoption> option = new list<selectoption>();   

          for(object__c design : [select name from object__c limit 10] )         
             option.add(new selectoption(design.name,design.name));
             return option;     
     } 

and using this in a query as

object1__c emailcontentinfo = [select field12__c from object1__c  where object__r.name =:field1 limit 1 ];

now I'm writing a trigger on another object(object3).In this need to get the values of field1....How can I get it...H

5
  • What is the relationship between the objects? Commented Nov 15, 2012 at 8:08
  • Call the method of the class to get the same values in the trigger Commented Nov 15, 2012 at 8:11
  • object1__c is a lookup for object__c.and object3 don't have any relation with this two objects.Is it possible to get the field1?
    – Eagerin Sf
    Commented Nov 15, 2012 at 8:13
  • declare the variable field1 as static and do classname.field1 in your trigger
    – Rao
    Commented Nov 15, 2012 at 8:15
  • What about bulkification? Can you be sure only one of these will come through at a time? If not you will have to add all values to a list and query for Object3 having those values. Commented Nov 15, 2012 at 8:34

1 Answer 1

4

If you make this a static property, it will be available for the duration of the transaction, thus you can refer to it in your trigger. E.g. assuming your class is MyClass:

public static string field1;
Public string getfield1(){return MyClass.field1;}
public void setTemplate(string field1){MyClass.field1 = field1;}

Then in the trigger you can have:

object1__c emailcontentinfo = [select field12__c from object1__c  where object__r.name =:MyClass.field1 limit 1 ];
1
  • better explained than my one liner :)
    – Rao
    Commented Nov 15, 2012 at 8:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .