+ Start a Discussion
Pedro SallesPedro Salles 

How to capture the ID of a contract in a trigger?

I created a trigger to invoke an apex class. The trigger is activated every time a contract is entered, i needed to get the ID of this contract, put it on the trigger and send it to my apex class, where i will conduct a query to send information to a partner Webservice.
I'm not finding content for this subject in Trailhead and developer.salesforce.
Could someone help me with this problem?

Thank you
Best Answer chosen by Pedro Salles
Niraj Kr SinghNiraj Kr Singh
Hi Pedro,

You can follow this code snipet and modify according to your further requirements.

/**** Trigger *****/
Trigger contractTrigger on Contract(after Insert) {
    contractTriggerHandler.processContract(trigger.newMap); //Here is your class calling
/*****Class ******/
public class contractTriggerHandler {
    public static void processContract(Map<Id, Contract> newContractMap) {
        Set<Id> contractIds = new Set<Id>();
        contractIds.addAll(newContractMap.keySet()); //Will get all new Contract Ids
        //Do your logic here to send information to a partner Webservice.

Hope it will help you.