You need to sign in to do that
Don't have an account?
Stefano Amenta
Illegal assignment from List<Contact> to Contact
Hi,
I'm working on this trigger but I get an error at this line:
Contact contacts = Trigger.new;
Illegal assignment from List<Contact> to Contact
Do you know why?
How should it be done correctly?
Thanks.
I'm working on this trigger but I get an error at this line:
Contact contacts = Trigger.new;
Illegal assignment from List<Contact> to Contact
Do you know why?
How should it be done correctly?
Thanks.
trigger TriggerAmbassadorUpdateCall on Contact (before insert, after insert, before update, after update) { system.debug('trigger new ***' + Trigger.new); system.debug('trigger new ***' + Trigger.old); //define variable data Contact contacts = Trigger.new; //create a set of contact Ids List<Id> contactIds = new List<Id>(); // Map<Id, String> contactMaps = new Map<Id, String>(); //loop through data for ( Contact contact : contacts ) { if( contact.Teacher_recuritment_status__c == 'Active' && contact.Ambassador__Short_Code__c!=null) { contactIds.add(contact.Id); } } if( Trigger.isUpdate) { //instantiate the class or create an object //fire method ambassador.fireCall(contactIds); } return; }
So it should be, Thanks,
Govindaraj.S
All Answers
So it should be, Thanks,
Govindaraj.S
It works now.
Firstly note that 'Trigger.new' returns a List of sObject and you use a single instance of Contact.That's why 'Illegal assignment from List<Contact> to Contact' error is occurred.So,try this 'use List<Contact> contacts=Trigger.new;'.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
You are creating a variable of contact and using it in for-each loop but you have to create a list of contact for using in for-each loop
Replace this of your code
Contact contacts = Trigger.new;
By this,
List<Contact> contacts = new List<Contact>();
contacts = Trigger.new;
and it will work.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha