You need to sign in to do that
Don't have an account?
Pranil Sarode
How to update same picklist values on different custom objects using trigger
I have two different custom objects "Speaker__C" and "Session__c" both having "city__c" picklist field.
If I update City value on one object same should be populated on other object.
Both picklist have same values.
If I update City value on one object same should be populated on other object.
Both picklist have same values.
instead of employe use write method in handler class.
trigger SessionTrigger on Session__c (after insert) {
if(trigger.isAfter && trigger.isInsert){
SessionTriggerApex.method(trigger.new);
}
}
Handler class:
public class SessionTriggerApex {
public static void method(List<Session__c> sessionList){
Set<Id> sessionID = new Set<Id>();
List<Speaker__c> speakerList = new List<Speaker__c>();
for(Session__c s : sessionList) {
Speaker__c speakerObj = new Speaker__c();
// if name field is auto number then does not need to insert name
speakerObj.Name = 'speaker name';
speakerObj.City__c = s.City__c;
speakerList.add(speakerObj);
}
insert speakerList;
}
}
Thanks,
Ajay Dubedi
All Answers
Try below code it work according to your requirement:
trigger:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Thank you for the solution, but I'm getting an error as " Method does not exist or incorrect signature: void method(List<Session__c>) from the type SessionTriggerApex"
- Pranil
instead of employe use write method in handler class.
trigger SessionTrigger on Session__c (after insert) {
if(trigger.isAfter && trigger.isInsert){
SessionTriggerApex.method(trigger.new);
}
}
Handler class:
public class SessionTriggerApex {
public static void method(List<Session__c> sessionList){
Set<Id> sessionID = new Set<Id>();
List<Speaker__c> speakerList = new List<Speaker__c>();
for(Session__c s : sessionList) {
Speaker__c speakerObj = new Speaker__c();
// if name field is auto number then does not need to insert name
speakerObj.Name = 'speaker name';
speakerObj.City__c = s.City__c;
speakerList.add(speakerObj);
}
insert speakerList;
}
}
Thanks,
Ajay Dubedi