You need to sign in to do that
Don't have an account?

If contact is associated to an opportunity and opportunity stage = "PreQual" THEN update Contact Picklist field to "PreQual Op Nurture"
How to write Trigger for this automation Logic-:
IF contact is associated to an opportunity and opportunity stage = "PreQual" THEN update Contact Picklist field to "PreQual Op Nurture"
IF contact associated to an opportunity and opportunity state = "Qualified", "Discovery", "Solution Overview", "Scoping", "Proposal", "Pending Approval","Won", "Closed Lost", or "Cancelled" THEN clear out Contact Picklist field to <None>
Please help, thanks!
IF contact is associated to an opportunity and opportunity stage = "PreQual" THEN update Contact Picklist field to "PreQual Op Nurture"
IF contact associated to an opportunity and opportunity state = "Qualified", "Discovery", "Solution Overview", "Scoping", "Proposal", "Pending Approval","Won", "Closed Lost", or "Cancelled" THEN clear out Contact Picklist field to <None>
Please help, thanks!
-----------------
trigger UpdateContact on Opportunity (after update) {
List<String> oppIdList = new List<String>();
for (Opportunity opp : Trigger.new) {
if (opp.StageName == 'PreQual') {
oppIdList.add(opp.Id);
} //end if
} // End of For
// query contact: assuming you have opportunity lookup at contact with field Opportunity__c
List<Contact> contactList = [Select Name,Email from Contact where Opportunity__c IN :oppIdList];
Set<Id> setContactList = new Set<Id>();
if(contactList!=null && !contactList.isEmpty()){
for(contact eachContact : contactList){
eachContact.yourPickListField = 'PreQual Op Nurture';
setContactList.add(eachContact.Id);
}
update contactList;
}
// update rest of contact as null
List<Contact> allContactList = [Select Name,Email from Contact where Opportunity__c IN : trigger.newMap.keySet()];
if(allContactList!=null && !allContactList.isEmpty()){
for(contact eachContact : allContactList){
if(setContactList!=null && !setContactList.contains(eachContact.Id)){
eachContact.yourPickListField = null;
}
}
update allContactList;
}
}
--------------
Please mark it best if it helps you. Thanks.
Regards,
Pawan Kumar
There, we are taking handle of all contacts from contacts role in opportunity.
I have Implement Trigger but it will throw error when Bulkify Opportunity we update .
Error-: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.MD98.updateContact: line 42, column
Below is my trigger