You need to sign in to do that
Don't have an account?
JohnDurai
Hi can somebody help me with solving this trigger? Here is my requirement.
I have a custom object customer project relationship with Opportunity. in my custom object i have status field and if the satus field is active then it shoud automatically check the checkbox in opportunity object ( I have created custom checkbox field in opportunity object). Below is my attempt to try but could not able to proceed further can someone guide me?
trigger Activeprojectopp4 on Customer_Project__c (after insert, after update) {
//storing the list of customer project recodrs added or updated
List<Customer_Project__c> cprecords=new list<Customer_Project__c>();
if(trigger.isinsert){
for(Customer_Project__c cp: trigger.new){
cprecords.add(cp);
}
}
//fetching the activerecords from customer project and puting into map
Map<id,Customer_Project__c> activerecords = new Map <id,Customer_Project__c>([select id,name,Opportunity__c from Customer_Project__c where status__c='Active']);
}
Thanks
trigger Activeprojectopp4 on Customer_Project__c (after insert, after update) {
//storing the list of customer project recodrs added or updated
List<Customer_Project__c> cprecords=new list<Customer_Project__c>();
if(trigger.isinsert){
for(Customer_Project__c cp: trigger.new){
cprecords.add(cp);
}
}
//fetching the activerecords from customer project and puting into map
Map<id,Customer_Project__c> activerecords = new Map <id,Customer_Project__c>([select id,name,Opportunity__c from Customer_Project__c where status__c='Active']);
}
Thanks
Set<Id> opportunityIDs = new Set<Id>();
for (Customer_Project__c cp : trigger.new) {
if (cp.Status__c == 'Active') {
opportunityIDs.add(cp.Opportunity__c);
}
}
if (!opportunityIDs.isEmpty()) {
List<Opportunity> opportunities = [SELECT Your_CheckBox_API__c
FROM Opportunity
WHERE Id IN : opportunityIDs];
for (Opportunity opp : opportunities) {
opp.Your_CheckBox_API__c = true;
}
update opportunities;
}
}
All Answers
Set<Id> opportunityIDs = new Set<Id>();
for (Customer_Project__c cp : trigger.new) {
if (cp.Status__c == 'Active') {
opportunityIDs.add(cp.Opportunity__c);
}
}
if (!opportunityIDs.isEmpty()) {
List<Opportunity> opportunities = [SELECT Your_CheckBox_API__c
FROM Opportunity
WHERE Id IN : opportunityIDs];
for (Opportunity opp : opportunities) {
opp.Your_CheckBox_API__c = true;
}
update opportunities;
}
}