Skip to main content
Dilip Kulkarni ha fatto una domanda in #Apex
Hi Experts,

I have one object 'service contract' where there is field 'owner' (lookup with user). In this field the value is put as owner. But I want to default the user creating the record as 'owner' (means owner of record) and he should have ability to reassign/change the value. In short I want to pull 'created by' value in 'owner' field once record is created. What will be trigger for it?

Regards.
3 risposte
  1. 29 giu 2017, 10:53
    Hi Dilip Kulkarni 12,

    Please try below trigger.

    I think this may help you.

    trigger FilOwner on service_contract__c(After insert) {

    list<service_contract__c>lstservicecontract = new list<service_contract__c>();

    service_contract__c oServicecontract;

    if(trigger.isAfter){

    system.debug('@developer-->After:');

    if(trigger.isInsert){

    system.debug('@developer-->isInsert:');

    for(service_contract__c oSC:trigger.new){

    oServicecontract = new service_contract__c();

    oServicecontract.Id = oSC.Id;

    oServicecontract.Owner = oSC.CreatedById;

    lstservicecontract.add(oServicecontract);

    system.debug('@developer-->oServicecontract:'+oServicecontract);

    }

    if(lstservicecontract.size()>0){

    update oServicecontract;

    }

    }

    }

    }

    Thanks

    Hemant

     
0/9000