You need to sign in to do that
Don't have an account?
venkata sainath
Primary contact
trigger validationPrimarycontact1 on Contact (after insert,after update) {
List<Contact> acclist = new List<Contact>();
set<Id> accIdSet = new set<Id>();
Set<Id> ContactIds = new Set<Id>();
if(Trigger.IsUpdate){
for ( Contact s : trigger.new ){
if(s.AccountId != null)
accIdSet.add(s.AccountId);
Contact oldcon = Trigger.oldMap.get(s.Id);
if(oldcon.id != null)
ContactIds.add(oldcon.id);
}
acclist=[select id, name,Account.name,Primary_Contact__c from Contact where AccountId IN : accIdSet AND Id NOT IN : ContactIds];
system.debug('*******Runish'+acclist);
List<Contact> conlist=new List<Contact>();
Contact c1=new Contact();
if(checkRecursive.runOnce()){
for ( Contact s : Trigger.new)
{
if(s.Primary_Contact__c ==true)
{
for(Contact a :acclist)
{
a.Primary_Contact__c =false;
c1=a;
}
update c1;
}
}
update acclist;
}
}
if(Trigger.isInsert){
for ( Contact s : trigger.new ){
if(s.AccountId != null)
accIdSet.add(s.AccountId);
Contact oldcon = Trigger.newMap.get(s.Id);
if(oldcon.id != null)
ContactIds.add(oldcon.id);
}
acclist=[select id, name,Account.name,Primary_Contact__c from Contact where AccountId IN : accIdSet AND Id NOT IN : ContactIds];
system.debug('*******Runish'+acclist);
List<Contact> conlist=new List<Contact>();
Contact c1=new Contact();
if(checkRecursive.runOnce()){
for ( Contact s : Trigger.new)
{
if(s.Primary_Contact__c ==true)
{
for(Contact a :acclist)
{
a.Primary_Contact__c =false;
c1=a;
}
update c1;
}
}
update acclist;
}
}
}
I am getting error that "Variable does not exist: checkRecursive",how to fix
List<Contact> acclist = new List<Contact>();
set<Id> accIdSet = new set<Id>();
Set<Id> ContactIds = new Set<Id>();
if(Trigger.IsUpdate){
for ( Contact s : trigger.new ){
if(s.AccountId != null)
accIdSet.add(s.AccountId);
Contact oldcon = Trigger.oldMap.get(s.Id);
if(oldcon.id != null)
ContactIds.add(oldcon.id);
}
acclist=[select id, name,Account.name,Primary_Contact__c from Contact where AccountId IN : accIdSet AND Id NOT IN : ContactIds];
system.debug('*******Runish'+acclist);
List<Contact> conlist=new List<Contact>();
Contact c1=new Contact();
if(checkRecursive.runOnce()){
for ( Contact s : Trigger.new)
{
if(s.Primary_Contact__c ==true)
{
for(Contact a :acclist)
{
a.Primary_Contact__c =false;
c1=a;
}
update c1;
}
}
update acclist;
}
}
if(Trigger.isInsert){
for ( Contact s : trigger.new ){
if(s.AccountId != null)
accIdSet.add(s.AccountId);
Contact oldcon = Trigger.newMap.get(s.Id);
if(oldcon.id != null)
ContactIds.add(oldcon.id);
}
acclist=[select id, name,Account.name,Primary_Contact__c from Contact where AccountId IN : accIdSet AND Id NOT IN : ContactIds];
system.debug('*******Runish'+acclist);
List<Contact> conlist=new List<Contact>();
Contact c1=new Contact();
if(checkRecursive.runOnce()){
for ( Contact s : Trigger.new)
{
if(s.Primary_Contact__c ==true)
{
for(Contact a :acclist)
{
a.Primary_Contact__c =false;
c1=a;
}
update c1;
}
}
update acclist;
}
}
}
I am getting error that "Variable does not exist: checkRecursive",how to fix
you are using checkRecursive class in your trigger to avoid it create below class.
I hope it helps you.
Thanks
Varaprasad
All Answers
you are using checkRecursive class in your trigger to avoid it create below class.
I hope it helps you.
Thanks
Varaprasad
Have you created the below class?
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}
else{
return run;
}
}
}
Tru creating this Apex Class, then save trigger