You need to sign in to do that
Don't have an account?
MS123456
How to write trigger this use case pls any on can help me its very Urgent.......
Hi Team Pls Help me....
Use Case:update below fields from the Most Recent Event corresponding to a contact with type="Call" to the Contact objects in Salesforce
Below are the fields which we are going to automate :
1.IsPrivate
2.StartDateTime
3.Subject
Only Using Trigger......
Use Case:update below fields from the Most Recent Event corresponding to a contact with type="Call" to the Contact objects in Salesforce
Below are the fields which we are going to automate :
1.IsPrivate
2.StartDateTime
3.Subject
Only Using Trigger......
<pre>
trigger MostRecentCall on Contact ( before update )
{
Map<Id,Contact> contactsWithCalls = new Map<Id,Contact>
( [ SELECT Id,
( SELECT Id, CallType // add other fields here
FROM Tasks
WHERE Type = 'Call'
ORDER BY CreatedDate DESC
LIMIT 1
)
FROM Contact
WHERE Id IN :Trigger.new
]
);
for ( Contact contact : Trigger.new )
{
Contact contactWithCall = contactsWithCalls.get( contact.Id );
if ( contactWithCall.Tasks.isEmpty() ) continue;
Task mostRecentCall = contactWithCall.Tasks[ 0 ];
contact.Most_Recent_Call_Type__c = mostRecentCall.CallType;
}
}
</pre>
Disclaimer: This code is untested and might contain typos.
Note also, that a Contact record will only be up-to-date immediately after it has been updated. If a "Call" Task is added to the Contact, but the Contact record itself is not updated, the Contact will not reflect the value(s) from the newer Task record. You can create a Task trigger (after insert, after update, after delete, after undelete) that updates the related Contact record(s).
thnx for the reply...
An event is a child object of contact Suppose one contact on Number of Events and the type is ='Call' and output will be the top most event will be updated?
Please Check this trigger,
If this code helped you then please mark this as best answer.