You need to sign in to do that
Don't have an account?
Marián Čekan
The problem is, my compound field Addres in Contact Point Address is always null. I don't know why as I can acces values of other fields. Can anyone help me please? Thanks a lot:)
Getting null instance of custom object
Hi, I'm working on trigger that will [after insert] get Street from ContactPointAddress object connected via lookup (Contact__c) and re-write MailingStreet field in Contact object ONLY if checkbox isDefault is checked. This is what I've done so far:
public static void AfterInsert(ContactPointAddress[] lstContactPointAddresses) { List<Contact> allPassagersToBeUpdated= new List<Contact>(); for (ContactPointAddress tmpContactPointAddress : lstContactPointAddresses) { // created contactPointAddress is checked - is default if (tmpContactPointAddress.IsDefault == true) { Contact passenger = [SELECT Name,LastName,MailingStreet FROM Contact WHERE Id =: tmpContactPointAddress.Contact__c]; Address addressCompoundField = (Address)tmpContactPointAddress.Address; passenger.MailingStreet = addressCompoundField.Street; allPassagersToBeUpdated.add(passenger); } else { return; } } if(allPassagersToBeUpdated.size()>0){ update allPassagersToBeUpdated; } }
The problem is, my compound field Addres in Contact Point Address is always null. I don't know why as I can acces values of other fields. Can anyone help me please? Thanks a lot:)
As mentioned here in the documentation, you can directly access Street field from ContactPointAddress..
https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contactpointaddress.htm
Please mark this as best answer if it helps you.!
Unfortunately didn't as I can't access fields Street,City,PostalCode right away from my tmpContactPointAddress as they access from lead.
I even tried to modify my code but nothing seems to work.
this is my next version: