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
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com 

Need help with trigger to change field of lookk up object---Plz help

Hi,

   I have an object C .Its has a filed called CProducer__c .That looks upto Producer Object. Producer__c has a field called Active( Checkbox set to false by default).

   Now I wanna toggle the value of checkbox to true(for the producer record, whose name is mentioned in C  record) , If An entry is made in C__c object with a particular producers name given in field CProducer__c.

 

Please help!!!!

Best Answer chosen by Admin (Salesforce Developers) 
Richa KRicha K

Hi Shrey,

 

I am not sure if this will help you. Please make appropriate changes you want in this. Also, optimise it.

 

trigger ConAccChck on Contact (after insert) 
{
    Map<Id,Account> mapAcc = new Map<Id,Account>();
    List<Account> lstAcc = new List<Account>();
    for(Account a : [select Id, Ic_Contact__c, Name from Account])
    {
        mapAcc.put(a.Id,a);
    }
    If(Trigger.IsAfter && Trigger.IsInsert)
    {
        for(Contact c : Trigger.New)
        {
         if(!mapAcc.IsEmpty())
           {
            mapAcc.get(c.AccountId).Ic_Contact__c = true;
            lstAcc.add(mapAcc.get(c.AccountId));
            }
        }
        update lstAcc;
    }
}

 

All Answers

Kunal01Kunal01

HI Shery,

 

 

Using Trigger you can do it.

 

Thanks;

KR

 

 

shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Well I know that.I was asking how to edit a field of look up object. I need the code for that!!!!

Kunal01Kunal01

Yes you need to code to update the parent record.

 

Thanks,

KR

shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Please dont waste my time as well as yours!!!!

Richa KRicha K

Hi Shrey,

 

I am not sure if this will help you. Please make appropriate changes you want in this. Also, optimise it.

 

trigger ConAccChck on Contact (after insert) 
{
    Map<Id,Account> mapAcc = new Map<Id,Account>();
    List<Account> lstAcc = new List<Account>();
    for(Account a : [select Id, Ic_Contact__c, Name from Account])
    {
        mapAcc.put(a.Id,a);
    }
    If(Trigger.IsAfter && Trigger.IsInsert)
    {
        for(Contact c : Trigger.New)
        {
         if(!mapAcc.IsEmpty())
           {
            mapAcc.get(c.AccountId).Ic_Contact__c = true;
            lstAcc.add(mapAcc.get(c.AccountId));
            }
        }
        update lstAcc;
    }
}

 

This was selected as the best answer
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Thanks a ton Shailesh. That was very helpfull. !!!!