-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPush_ClosedWon_to_ChargeOver.apxt
58 lines (48 loc) · 1.69 KB
/
Push_ClosedWon_to_ChargeOver.apxt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
trigger Push_ClosedWon_to_ChargeOver on Opportunity (after update)
{
List<sObject> objs = new List<sObject>();
System.debug('Trigger running...');
if (Trigger.isInsert || Trigger.isUpdate)
{
System.debug('Checking for closed-won...');
// Catch closed-win opportunities in Salesforce
for (Opportunity o : Trigger.new)
{
if (o.isWon &&
!Trigger.oldMap.get(o.Id).isWon)
{
System.debug('Found a closed-won opportunity');
objs.add(o);
}
}
}
/*else if (Trigger.isDelete)
{
for (sObject o : Trigger.old)
{
objs.add(o);
}
}*/
for (integer i = 0; i < objs.size(); i++)
{
System.debug('Account ID is: ' + (String) objs[i].get('AccountId'));
List<Account> a = [SELECT Id, Name FROM Account WHERE Id = :(String) objs[i].get('AccountId')];
if (a != null && a.size()>0)
{
System.debug('Found the account for the opportunity... pushing to ChargeOver');
Map<String, String> va = new Map<String, String>();
va.put('company', (String) a[0].Name);
va.put('external_key', (String) a[0].Id);
ChargeOver.toCustomer(JSON.serialize(va));
Map<String, String> v = new Map<String, String>();
v.put('customer_external_key', (String) objs[i].get('AccountId'));
v.put('paycycle', 'mon'); // Monthly
v.put('external_key', (String) objs[i].get('Id'));
ChargeOver.toSubscription(JSON.serialize(v));
}
else
{
System.debug('Account not found?');
}
}
}