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
Nikhil shah 3Nikhil shah 3 

hi all i am writting trriger on custom field i want create task on field which has look up thanks in advance

David "w00t!" LiuDavid "w00t!" Liu
Nikhil can you elaborate your specific requirements?

P.S. you can create tasks using workflows, which might save you some time instead of coding!
Nikhil shah 3Nikhil shah 3
SObjectType objToken = Schema.getGlobalDescribe().get('smagicinteract__Incoming_SMS__c');
    DescribeSObjectResult objDef = objToken.getDescribe();
    Schema.DisplayType fieldType ;

    Map<String, SObjectField> fields = objDef.fields.getMap();
for(String s:fields.keySet()){
    
       Schema.DescribeFieldResult f=fields.get(s).getDescribe();
                    
       fieldType = f.getType();
       if(fieldType == Schema.DisplayType.REFERENCE){     
             if(f.isCustom()){
                  System.debug(s);
                     
                
             }
       }
    }

now i get custom field which has lookup. now i want to write trigger on smagicinteract__Incoming_SMS__c which filed has lookup i have to create one task

for(smagicinteract__Incoming_SMS__c sms : Trigger.new){
                         
                          ilist.add(sms);
                       
                     //  incomingidmap.put(sms,);       here i require lookup field id dynamically
                       System.debug('=----'+incomingidmap);
                           
                 }
thanks in advance
David "w00t!" LiuDavid "w00t!" Liu
Let me see if I can figure out what you're looking for:

1. Dynamically get all fields on an object that are Lookup fields
2. Find every record in your trigger that has a Lookup field populated
3. Create a task for that record with the Lookup field name/values

Is this correct?  If so you're almost there  =)
David