+ Start a Discussion
Admin 123Admin 123 

The logic is when we create Customer Project for an Opportunity with the Status=Active, then Active Customer project check box on the Opportunity detail page is automatically checked.

 The logic is when we create Customer Project(Custom obj) for an Opportunity(Standard obj) with the Status=Active(Picklist value), then Active Customer project check box on the Opportunity detail page is automatically checked.
wherein there is lookup between Customer Project and Opportunity..!
 
Best Answer chosen by Admin 123
Deepak Maheshwari 7Deepak Maheshwari 7
 trigger trg3 on Customer_Project__c (after insert) {
    if(trigger.isinsert){
        list<Id> accIdList = new list<id>();
        for(Customer_Project__c c : trigger.new){
        if(status__c=='Active')
        {
           accIdList.add(c.Opportunities_CP__c); 
        }}

         list<Opportunity> acc = [SELECT id,Active_Customer_project from Opportunity WHERE id in: accIdList];
            for(Opportunity a : acc){
                a.Active_Customer_project = true;
              }
         update acc;
    }
}

All Answers

Deepak Maheshwari 7Deepak Maheshwari 7
Please Confirm Opportunity is parent of Customer Project
Deepak Maheshwari 7Deepak Maheshwari 7

This can be done through process builder and trigger.

Admin 123Admin 123
User-added image

these fields belongs to Customer Project object
Admin 123Admin 123
I created Process builder but its not updating.
Admin 123Admin 123
How will be the trigger for it..Please help as i am new to this technology. 
Deepak Maheshwari 7Deepak Maheshwari 7
 trigger trg3 on Customer_Project__c (after insert) {
    if(trigger.isinsert){
        list<Id> accIdList = new list<id>();
        for(Customer_Project__c c : trigger.new){
        if(status__c=='Active')
        {
           accIdList.add(c.Opportunities_CP__c); 
        }}

         list<Opportunity> acc = [SELECT id,Active_Customer_project from Opportunity WHERE id in: accIdList];
            for(Opportunity a : acc){
                a.Active_Customer_project = true;
              }
         update acc;
    }
}
This was selected as the best answer
rajat Maheshwari 6rajat Maheshwari 6

Hi Admin,

Please use this below code snippet, Hope it will helps you :)

trigger CustomerProjectTrigger on Customer_Project__c (before insert)
 {
    set<Id> OppSet = new Set<Id>();
    Map<Id,Opportunity> mp_Opp;

    for(Customer_Project__c  CustomerProject : Trigger.new)
      {
         if(CustomerProject.Status__c=='Active')
               OppSet.add(CustomerProject.Opportunities_CP__c);
      
      }

if(OppSet!=null && OppSet.size()>0)
  {

 mp_Opp = new Map<Id,Opportunity>([Select Id,ActiveCustomerProjectField from Opportunity where Id IN:OppSet]);

   }

for(Customer_Project__c  CustomerProject : Trigger.new)
   {
      if(mp_Opp!=null && mp_Opp.containsKey(CustomerProject.Opportunities_CP__c))
        {
             mp_Opp.get(CustomerProject.Opportunities_CP__c).ActiveCustomerProjectField  = true;

         }

   }

if(mp_Opp!=null && mp_Opp.values()!=null)
    update mp_Opp.values();

}


In above code, Please use correct API Name for -:

1. "Customer_Project__c" (Customer Project Object)

2. ActiveCustomerProjectField (Opportunity Field)

 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

Admin 123Admin 123
@Deepak Maheshwari Thanks so much, it worked. So simple and easy one.

@Rajat maheshwari Even this worked, but unfortunately I can give only one best Answer.