+ Start a Discussion
Sunil Kumar 545Sunil Kumar 545 

if contact as two checkbox (accept and reject) and lookup with two object contact and book.if we accept in contact object it automatically accept in book object using triggers

Ajay K DubediAjay K Dubedi
Hi Sunil,

Please try this code.

trigger UpadteBookCheckBoxTrigger1 on Contact (after update) {
    
    set <id> IdCollect = new Set<Id>(); 
    for(Contact con:Trigger.New){
        if(con.Book__c!=Null){
            IdCollect.add(con.Book__c);
        }
    }
    
    List <Book__c> bkList = [SELECT Accept__c From Book__c WHERE Id IN :IdCollect];
    System.debug('boo'+bkList);
    
    for(Contact c:Trigger.New){
        if(bkList.size()>0){
            for(Book__c bk:bkList){
                if(c.Accept__c==true){
                    bk.Accept__c=true;
                }
            }
        }
    }
    update bkList;
}
    
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi
Sunil Kumar 545Sunil Kumar 545
In contact only have create accept and reject checkbox  but in book object have to create picklist value like status=accept,reject,pending.if contact checkbox accept book object also be accept,if its rejected same thing,record created means pending uisng triggers
 
Sunil Kumar 545Sunil Kumar 545
can anyone tell this requirement?