• Abraham kumar
  • NEWBIE
  • 80 Points
  • Member since 2014
  • Cognizant Technologies

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 37
    Replies
Hi All,

The below trigger is working fine on insert and update operations but on delete it gives me the below error. can you please help me

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contactcallout caused an unexpected exception, contact your administrator: Contactcallout: execution of BeforeDelete caused by: System.FinalException: Record is read-only: Trigger.Contactcallout: line 11, column 1". 


Click here to return to the previous page.
trigger Contactcallout on Contact (after insert, after update, before delete) {
Id RecordType1= [SELECT Id FROM RecordType WHERE SOBJECTTYPE=:'Contact' AND DeveloperName=:'Commercial'].Id;
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
if(Trigger.isDelete)
    {
        for (contact c : Trigger.old) 
        {
            if(c.RecordTypeId == RecordType1 && c.Reg__c == TRUE)    
            c.Status__c='Inactive';
            {
                validContacts.add(c);
                accIds.add(c.accountid);
            }   
        }
    }
    else
    {
for (contact c : Trigger.new) {
    if(c.RecordTypeId == RecordType1 && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Registered_on_ITV_Media__c == TRUE)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
                }
                }
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
              }
}

 
HI All,

I have the below trigger and test class and with this test class i can get only 69% code coverage, can you pls help me increase code coverage for below trigger so i will be able to deploy this to production.
trigger Contactcallout on Contact (after insert, after update, before delete) {
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
if(Trigger.isDelete)
    {
        for (contact c : Trigger.old) 
        {
            if(c.RecordTypeId == '012D0000000BaFA' && c.Reg__c == TRUE)
            c.status__c='inactive';
            {
                validContacts.add(c);
                accIds.add(c.accountid);
            }   
        }
    }
    else
    {
for (contact c : Trigger.new) {
    if(c.RecordTypeId == '012D0000000BaFA' && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Reg__c == TRUE)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
                }
                }
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
              }
}
Test Classs:-
@istest
public class ContactcalloutTestClass{
@istest
static void contactcreate(){
Account acc = new Account();
acc.Name = 'Test';
acc.ShippingStreet = 'test';
acc.ShippingCity = 'test';        
acc.ShippingPostalCode = 'tw31aq';
insert acc;

contact c =new contact();
c.Email = 'abc@gmail.com';
c.Salutation = 'Mr';
c.FirstName = 'Abraham';
c.LastName = 'Daniel';
c.type__c = 'Agency';
c.status__c= 'Active';
insert c;

Contact c1=[Select id from contact Where Id =:c.id];
c1.firstname= 'Daniel';
c1.lastname= 'Abraham';
c1.Email = 'def@gmail.com';
c1.Status__c = 'inactive';
update c1;
           try
           { 
               Delete c1;
              // c1.Status__c = 'Inactive';
            }
           catch(DmlException e) 
           {
               System.debug('The following exception has occurred: ' + e.getMessage());
            }
               }
@istest
static void contactcreate2(){
Account acc2 = new Account();
acc2.Name = 'Test';
acc2.ShippingStreet = 'test';
acc2.ShippingCity = 'test';        
acc2.ShippingPostalCode = 'tw31aq';
insert acc2;

contact c3 =new contact();
c3.Email = 'abc@gmail.com';
c3.Salutation = 'Mr';
c3.FirstName = 'Abraham';
c3.LastName = 'Daniel';
c3.type__c = 'Agency';
c3.status__c= 'Active';
insert c3;

Contact c4=[Select id from contact Where Id =:c3.id];
c4.firstname= 'Daniel';
c4.lastname= 'Abraham';
c4.Email = 'def@gmail.com';
c4.Status__c = 'inactive';
update c4;
if(c4.email !=c3.email||c4.firstname != c3.firstname||c4.lastname != c3.lastname){
Test.setMock(WebServiceMock.class, new WebServiceMockImpl());
            }
            }
            }

I have checked in the developer console and see the lines 21 to lines 32 of the trigger are not being covered. PLease help me increase code coverage to deploy this code. 

Many Thanks 
Abraham
 
Hi All.
I have the below trigger and test class and with this test class i can get only 69% coverage, can you please help to increase code coverage for below trigger.
Trigger:-
trigger Contactcallout on Contact (after insert, after update, before delete) {
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
if(Trigger.isDelete)
    {
        for (contact c : Trigger.old) 
        {
            if(c.RecordTypeId == '012D8798757BaFA' && c.Registered__c == TRUE)
            c.status__c='inactive';
            {
                validContacts.add(c);
                accIds.add(c.accountid);
            }   
        }
    }
    else
    {
for (contact c : Trigger.new) {
    if(c.RecordTypeId == '012D9876545BaFA' && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Registered__c == TRUE)
    //  if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
                }
                }
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
              }
}

Test Class:-
@istest
public class ContactcalloutTestClass{
@istest
 static void contactcreate(){
contact c =new contact();
c.Email = 'abc@gmail.com';
c.Salutation = 'Mr';
c.FirstName = 'Abraham';
c.LastName = 'Daniel';
c.type__c = 'Agency';
c.status__c= 'Active';

insert c;
c.firstname= 'Daniel';
c.lastname= 'Abraham';
c.Email = 'def@gmail.com';
c.Status__c = 'active';
update c;
           try
           { 
               Delete c;
              // c1.Status__c = 'Inactive';
            }
           catch(DmlException e) 
           {
             System.debug('The following exception has occurred: ' + e.getMessage());
            }
            }
}

Many Thanks for your help in advance
Abraham
Hi All,

i have a trigger on account object which upon delete action sends notification of the related contacts of the account to an external system, Now i want a particular field called status__c in contact to be changed to value "inactive" once the trigger is fired. The status__c field update to "inactive" should only happen on delete action. Please help me achieve this in below trigger.
trigger Contactcallout2 on Account(after update, before delete) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
if(Trigger.IsBefore && Trigger.IsDelete){
for(Account acct : trigger.old) {
             acctIds.add(acct.Id);     
    }
    }
    else{
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);  
             }     
    }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '012D1676545BaFA']){
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
   }

 
Hi All,

I am having below trigger which calls a method "sendNotification" when the account name is changed. I want this trigger to call the method when the account is deleted ie)on before delete operation. Please help me on how this can be done.
trigger Contactcallout2 on Account(after update) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);      
    }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '012D6765454BaFA']){
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
   }
Many Thanks in advance
Abraham
 
Hi All,

Please help me with this trigger. It currently calls a class called webservicecallout and send notification method on insert and update actions. I want it to also call this class and method once the contact is deleted.. Please help
trigger Contactcall on Contact (after insert, after update) {
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
for (contact c : Trigger.new) {
    if(c.RecordTypeId == '012D7865454BaFA' && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c1 : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
            
    
    }
}
}

Many Thanks in advance
Abraham
Hi All,

I want to deploy below trigger and test class in production which has 87% code coverage. But while i validate Im getting CODE COVERAGE ERROR .My overall code coverage is 74 % i need 1 more % to deploy Please help me with what needs to be done to get 1%. to deploy
trigger ContactTrig2 on Account(after update) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);
        }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '012D0045000BgasT']){
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
   
}

Test class:-
will increasing code coverage of below test class which is 87% solve it?please let me know
@istest
public class Contacttrig2TestClass{
@istest
static void Accountcreate(){
Account a =new Account();
a.Name = 'abc';
a.Type = 'Agency';
a.ShippingStreet = 'test';
a.ShippingCity = 'test';
a.ShippingPostalCode = 'tw31aq';
insert a;
a.Name = 'abcd';
update a;
contact c =new contact();
c.Email = 'abc@wipro.com';
c.Salutation = 'Mr';
c.FirstName = 'Test';
c.LastName = 'Tester';
c.type__c = 'Agency';
c.status__c= 'Active';
insert c;
    }
    }

Thanks
Abraham 
HI All,

Please help me for test class for the below Trigger im getting just 62% coverage
trigger ContactTrig on Account(after update) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);
        }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '034D0000000CVERt'])
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
}
My Test class is as below please let me know what im missing 
@istest
public class ContactTrig2TestClass{
 static void Accountcreate(){
Account c =new Account();
c.Name = 'Testcon';
c.Type = 'Agency';
insert c;
c.Name = 'Testcontract';
update c;
}
 }



 
HI All,

Please help me for test class for the below Trigger im getting just 62% coverage 
trigger ContactTrig on Account(after update) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);
        }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '034D0000000CVERt']){
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
   
}

My Test class is as below
@istest
public class ContactTrig2TestClass{
 static void Accountcreate(){
Account c =new Account();
c.Name = 'Testcon';
c.Type = 'Agency';
insert c;
c.Name = 'Testcontract';
update c;
}
 }

Many Thanks
Abraham
 
i just need to do a POST request containing all the contact data fields whenever a user is created or updated on Salesforce and sent to our client website database. 

Please help me with class and POST method to achieve this,code on how this can be done.
Im a bit new with integration, any help highly appreciated. Please help me complete this on what needs to be done.

It is just the post method please help.

Many Thanks
Abraham
Hi All,

The below trigger is working fine on insert and update operations but on delete it gives me the below error. can you please help me

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contactcallout caused an unexpected exception, contact your administrator: Contactcallout: execution of BeforeDelete caused by: System.FinalException: Record is read-only: Trigger.Contactcallout: line 11, column 1". 


Click here to return to the previous page.
trigger Contactcallout on Contact (after insert, after update, before delete) {
Id RecordType1= [SELECT Id FROM RecordType WHERE SOBJECTTYPE=:'Contact' AND DeveloperName=:'Commercial'].Id;
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
if(Trigger.isDelete)
    {
        for (contact c : Trigger.old) 
        {
            if(c.RecordTypeId == RecordType1 && c.Reg__c == TRUE)    
            c.Status__c='Inactive';
            {
                validContacts.add(c);
                accIds.add(c.accountid);
            }   
        }
    }
    else
    {
for (contact c : Trigger.new) {
    if(c.RecordTypeId == RecordType1 && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Registered_on_ITV_Media__c == TRUE)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
                }
                }
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
              }
}

 
HI All,

I have the below trigger and test class and with this test class i can get only 69% code coverage, can you pls help me increase code coverage for below trigger so i will be able to deploy this to production.
trigger Contactcallout on Contact (after insert, after update, before delete) {
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
if(Trigger.isDelete)
    {
        for (contact c : Trigger.old) 
        {
            if(c.RecordTypeId == '012D0000000BaFA' && c.Reg__c == TRUE)
            c.status__c='inactive';
            {
                validContacts.add(c);
                accIds.add(c.accountid);
            }   
        }
    }
    else
    {
for (contact c : Trigger.new) {
    if(c.RecordTypeId == '012D0000000BaFA' && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Reg__c == TRUE)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
                }
                }
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
              }
}
Test Classs:-
@istest
public class ContactcalloutTestClass{
@istest
static void contactcreate(){
Account acc = new Account();
acc.Name = 'Test';
acc.ShippingStreet = 'test';
acc.ShippingCity = 'test';        
acc.ShippingPostalCode = 'tw31aq';
insert acc;

contact c =new contact();
c.Email = 'abc@gmail.com';
c.Salutation = 'Mr';
c.FirstName = 'Abraham';
c.LastName = 'Daniel';
c.type__c = 'Agency';
c.status__c= 'Active';
insert c;

Contact c1=[Select id from contact Where Id =:c.id];
c1.firstname= 'Daniel';
c1.lastname= 'Abraham';
c1.Email = 'def@gmail.com';
c1.Status__c = 'inactive';
update c1;
           try
           { 
               Delete c1;
              // c1.Status__c = 'Inactive';
            }
           catch(DmlException e) 
           {
               System.debug('The following exception has occurred: ' + e.getMessage());
            }
               }
@istest
static void contactcreate2(){
Account acc2 = new Account();
acc2.Name = 'Test';
acc2.ShippingStreet = 'test';
acc2.ShippingCity = 'test';        
acc2.ShippingPostalCode = 'tw31aq';
insert acc2;

contact c3 =new contact();
c3.Email = 'abc@gmail.com';
c3.Salutation = 'Mr';
c3.FirstName = 'Abraham';
c3.LastName = 'Daniel';
c3.type__c = 'Agency';
c3.status__c= 'Active';
insert c3;

Contact c4=[Select id from contact Where Id =:c3.id];
c4.firstname= 'Daniel';
c4.lastname= 'Abraham';
c4.Email = 'def@gmail.com';
c4.Status__c = 'inactive';
update c4;
if(c4.email !=c3.email||c4.firstname != c3.firstname||c4.lastname != c3.lastname){
Test.setMock(WebServiceMock.class, new WebServiceMockImpl());
            }
            }
            }

I have checked in the developer console and see the lines 21 to lines 32 of the trigger are not being covered. PLease help me increase code coverage to deploy this code. 

Many Thanks 
Abraham
 
Hi All.
I have the below trigger and test class and with this test class i can get only 69% coverage, can you please help to increase code coverage for below trigger.
Trigger:-
trigger Contactcallout on Contact (after insert, after update, before delete) {
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
if(Trigger.isDelete)
    {
        for (contact c : Trigger.old) 
        {
            if(c.RecordTypeId == '012D8798757BaFA' && c.Registered__c == TRUE)
            c.status__c='inactive';
            {
                validContacts.add(c);
                accIds.add(c.accountid);
            }   
        }
    }
    else
    {
for (contact c : Trigger.new) {
    if(c.RecordTypeId == '012D9876545BaFA' && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID||c.Registered__c == TRUE)
    //  if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
                }
                }
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
              }
}

Test Class:-
@istest
public class ContactcalloutTestClass{
@istest
 static void contactcreate(){
contact c =new contact();
c.Email = 'abc@gmail.com';
c.Salutation = 'Mr';
c.FirstName = 'Abraham';
c.LastName = 'Daniel';
c.type__c = 'Agency';
c.status__c= 'Active';

insert c;
c.firstname= 'Daniel';
c.lastname= 'Abraham';
c.Email = 'def@gmail.com';
c.Status__c = 'active';
update c;
           try
           { 
               Delete c;
              // c1.Status__c = 'Inactive';
            }
           catch(DmlException e) 
           {
             System.debug('The following exception has occurred: ' + e.getMessage());
            }
            }
}

Many Thanks for your help in advance
Abraham
Hi All,

i have a trigger on account object which upon delete action sends notification of the related contacts of the account to an external system, Now i want a particular field called status__c in contact to be changed to value "inactive" once the trigger is fired. The status__c field update to "inactive" should only happen on delete action. Please help me achieve this in below trigger.
trigger Contactcallout2 on Account(after update, before delete) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
if(Trigger.IsBefore && Trigger.IsDelete){
for(Account acct : trigger.old) {
             acctIds.add(acct.Id);     
    }
    }
    else{
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);  
             }     
    }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '012D1676545BaFA']){
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
   }

 
Hi All,

I am having below trigger which calls a method "sendNotification" when the account name is changed. I want this trigger to call the method when the account is deleted ie)on before delete operation. Please help me on how this can be done.
trigger Contactcallout2 on Account(after update) {
List<Contact> ListContact = new List<Contact>();
Set<ID> acctIds = new set<ID>();
    for(Account acct : trigger.new) {
        if(Trigger.oldMap.get(acct.id).Name != acct.Name){
             acctIds.add(acct.Id);      
    }
    }
    if(acctIds.size() > 0){
        for(Contact con : [SELECT id,Email,FirstName,LastName,phone,Title__c,Account.Name,status__c, AccountId FROM Contact WHERE AccountId IN : acctIds AND RecordTypeid = '012D6765454BaFA']){
          WebServiceCallout.sendNotification(con.Id,con.Email,con.FirstName,con.LastName,con.phone,con.Title__c,con.Account.Name,con.status__c);
        }
    }
   }
Many Thanks in advance
Abraham
 
Hi All,

Please help me with this trigger. It currently calls a class called webservicecallout and send notification method on insert and update actions. I want it to also call this class and method once the contact is deleted.. Please help
trigger Contactcall on Contact (after insert, after update) {
Map<Id, String> m = new Map<Id, String>();
list<Contact> validContacts = new list<Contact>();
set<ID> accIds = new set<ID>();
for (contact c : Trigger.new) {
    if(c.RecordTypeId == '012D7865454BaFA' && c.Reg__c == TRUE){
    if(Trigger.isUpdate){
        contact old = Trigger.oldMap.get(c.Id);
        if (c.Email != old.Email||c.FirstName!=old.FirstName||c.LastName!=old.LastName||c.phone!=old.phone||c.Title__c!=old.Title__c||c.status__c!=old.status__c||c.AccountID!=old.AccountID)
         {
             validContacts.add(c);
                accIds.add(c.accountid);
         }
         }else{
         validContacts.add(c);
                accIds.add(c.accountid);
         }   
}
map<ID, Account> accMap;
if(!accIds.IsEmpty()) // guard condition for SOQL
    accMap = new map<ID, Account>([select name from account where id in :accIds]);

for (contact c1 : validContacts) {
    Account acc = accMap.get(c.AccountID);
    string accName = acc == null ? null : acc.Name;
    WebServiceCallout.sendNotification(c.Id,c.Email,c.FirstName,c.LastName,c.phone,c.Title__c,accName,c.status__c);
            
    
    }
}
}

Many Thanks in advance
Abraham