You need to sign in to do that
Don't have an account?
Suman Bonthala
how to convert trigger into class
Trigger NoRelation on Candidate__c(After Insert,After Update)
{
List<Candidate__c> updcanlist= new List<Candidate__c>();
if(Utility.flag!=true)
{
map<Id,Id> canmap= new map<Id,Id>();
for(Candidate__c c:trigger.new)
{
canmap.put(c.Id,c.Opportunity_Relation__c);
}
map<Id,string> oppmap= new map<Id,string>();
List<opportunity> opplist= [Select id,name,Emp_Number__c from opportunity where Id IN:canmap.values()];
for(opportunity opp:opplist)
{
oppmap.put(opp.Id,opp.Emp_Number__c);
}
map<string,Id> empmap= new map<string,Id>();
List<Employee__c> emplist= [Select id,name,Emp_Number__c from Employee__c where Emp_Number__c IN:oppmap.values()];
for(Employee__c emp:emplist)
{
empmap.put(emp.Emp_Number__c,emp.Id);
}
List<Candidate__c> canlist=[select id,name,Opportunity_Relation__c,Emp_RecordID__c from Candidate__c where Id IN:canmap.keyset()];
for(Candidate__c can:canlist)
{
Candidate__c c= new Candidate__c();
c.Id=can.Id;
c.Emp_RecordID__c=empmap.get(oppmap.get(can.Opportunity_Relation__c));
updcanlist.add(c);
}
}
Utility.flag=true;
if(updcanlist.size()>0)
{
update updcanlist;
}
}
{
List<Candidate__c> updcanlist= new List<Candidate__c>();
if(Utility.flag!=true)
{
map<Id,Id> canmap= new map<Id,Id>();
for(Candidate__c c:trigger.new)
{
canmap.put(c.Id,c.Opportunity_Relation__c);
}
map<Id,string> oppmap= new map<Id,string>();
List<opportunity> opplist= [Select id,name,Emp_Number__c from opportunity where Id IN:canmap.values()];
for(opportunity opp:opplist)
{
oppmap.put(opp.Id,opp.Emp_Number__c);
}
map<string,Id> empmap= new map<string,Id>();
List<Employee__c> emplist= [Select id,name,Emp_Number__c from Employee__c where Emp_Number__c IN:oppmap.values()];
for(Employee__c emp:emplist)
{
empmap.put(emp.Emp_Number__c,emp.Id);
}
List<Candidate__c> canlist=[select id,name,Opportunity_Relation__c,Emp_RecordID__c from Candidate__c where Id IN:canmap.keyset()];
for(Candidate__c can:canlist)
{
Candidate__c c= new Candidate__c();
c.Id=can.Id;
c.Emp_RecordID__c=empmap.get(oppmap.get(can.Opportunity_Relation__c));
updcanlist.add(c);
}
}
Utility.flag=true;
if(updcanlist.size()>0)
{
update updcanlist;
}
}
Greetings to you!
Please try below code:
Trigger:
Handler Class:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
I found a link please refer to this below link:
https://developer.salesforce.com/forums/?id=906F0000000A1lmIAC
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Greetings to you!
Please try below code:
Trigger:
Handler Class:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas