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
harish reddy 50harish reddy 50 

How make check box ticked using trigger..?

Hi,
     I have two objects one is standard object(contact) and coustom(Payment__c) and thay have lookup from Payment to contacts .My requirement when ever payment record is created corresponding confirmpaymnt checkbox on contact should be tickked.
I have tried trigger but functionality not working can any one help me with this.
Thanks in Advance.

TRIGGER:

rigger checkboTrigger on Payment__c(after Insert) {

List<id> ids = new List<id>();
List<contact> conn3 = new List<contact>();

for(Payment__c pay: Trigger.new)
{
    ids.add(pay.id);
}

List<contact> conn2 = [SELECT id ,PaymentConfimed__c from contact  where id in: ids];

  for(contact conn :conn2)
  {
  
      conn.PaymentConfimed__c = true;
         conn3.add(conn);
  }
    update conn3; 
Raj VakatiRaj Vakati
trigger checkboTrigger on Payment__c(after Insert) {
List<id> ids = new List<id>();
for(Payment__c pay: Trigger.new)
{
    ids.add(pay.contact__c);
}

List<contact> conn2 = [SELECT id ,PaymentConfimed__c from contact  where id in: ids];

  for(contact conn :conn2)
  {
      conn.PaymentConfimed__c = true;
  }
    update conn2; 
    }
Raj VakatiRaj Vakati
Use the above code . It will solve 
Amit Chaudhary 8Amit Chaudhary 8
Please update your cod elike below
trigger checkboTrigger on Payment__c(after Insert) 
{
	Set<id> ids = new Set<id>(); // Try to use set to avoid duplicate record
	
	for(Payment__c pay: Trigger.new)
	{
		if(pay.contact__c != null )
		{
			ids.add(pay.contact__c);
		}	
	}

	if(ids.size() > 0 )
	{
		List<contact> listContact = [SELECT id ,PaymentConfimed__c from contact  where id in :ids ];
		
		for(contact conn :listContact)
		{
			conn.PaymentConfimed__c = true;
		}
		
		update listContact; 
	}	
}

Let us know if this will help you

 
D-CoderD-Coder
No need of trigger and writing code. Use process builder , it can update parent record (Contact) on insertion of child(Payment__c).
Develop process builder flow on object Payment__c , you can update fields of its parent.