Professional Documents
Culture Documents
if(accMap.get(con.AccountId).SLA__c=='Silver'){
con.Level__c='Secondary';
}
}
}
}
if(!conList.isEmpty())
Database.update(conList,false);
}
---------------------------------------------------------------------------------
#create a trigger Rating is Hot then LeadSource Is Web.
trigger AccountToContactHotTrigeer on Account (after update) {
Map<Id,Account> accMap=new Map<Id,Account>();
for(Account acc:trigger.new){
if(trigger.Isupdate && acc.rating=='Hot'&& acc.rating!
=trigger.OldMap.get(acc.id).rating ){
accmap.put(acc.Id, acc);
}
}
List<contact>conList=[select Id,AccountId from contact where AccountId
in:accMap.keySet()];
if(conList.size()>0){
for(contact con:conList){
if(accMap.containsKey(con.AccountId)){
if(accMap.get(con.AccountId).rating=='Hot'){
con.LeadSource='Web';
}
}
}
}
if(!conList.isEmpty())
Database.update(conList,false);
}
-----------------------------------------------------------------------------------
-----
# Child to Parent
trigger ContactToAccountSLATrigger on Contact (after insert, after update){
Set<Id> accIDSet=new Set<Id>();
for(contact con:trigger.new){
if(trigger.Isinsert && con.Level__c!=null && con.AccountId!=null){
accIDSet.add(con.AccountId);
}
if(trigger.Isupdate && con.Level__c!=null && con.AccountId!=null){
if(trigger.OldMap.get(con.Id).Level__c!=con.Level__c){
accIDSet.add(con.AccountId);
}
}
}
Map<Id,Account> accMap=new Map<Id,Account>();
for(Account a:[select Id,SLA__c from Account where Id in:accIDSet]){
accMap.put(a.Id,a);
}
List<Account> newUpdateList= new List<Account>();
if(!accMap.isEmpty()){
for(contact con:trigger.new){
if(accMap.containsKey(con.AccountId)){
Account a=new Account();
a.Id=con.AccountId;
if(con.Level__c=='Primary'){
a.SLA__c='Gold';
}
if(con.Level__c=='Secondary'){
a.SLA__c='Silver';
}
if(con.Level__c=='Tertiary')
{
a.SLA__c='Platinum';
}
newUpdateList.add(a);
}
}
}
if(!newUpdateList.isEmpty())
Database.update(newUpdateList);
}
-----------------------------------------------------------------------------------
---------
#Child To Parent
trigger TriggerOptyUpdateAccount on Opportunity (after insert,after update) {
Set<Id> accIDSet=new Set<Id>();
for( Opportunity Opp:trigger.new){
if(trigger.Isinsert && Opp.StageName!=null && Opp.Type!=null){
accIDSet.add(Opp.AccountId);
}
if(trigger.Isupdate && Opp.StageName!=null && Opp.Type!=null){
if(trigger.OldMap.get(Opp.Id).StageName!=Opp.StageName &&
trigger.OldMap.get(Opp.Id).Type!=Opp.Type){
accIDSet.add(Opp.AccountId);
}
}
}