-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapex_ContractRenewerOpp.cls
32 lines (27 loc) · 1.03 KB
/
apex_ContractRenewerOpp.cls
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
/**
* Simple Class to use the Renew API to renew a contract
*/
public with sharing class ContractRenewerOpp {
public Opportunity opp { get; private set; }
public ContractRenewerOpp(ApexPages.StandardController controller) {
opp = (Opportunity) controller.getRecord();
}
@AuraEnabled
public static PageReference renewContract(List<Contract> renewedContracts, Id oppId) {
try {
ContractRenewer renewer = new ContractRenewer();
RenewalContext input = new RenewalContext();
input.masterContractId = null;
input.renewedContracts = renewedContracts;
if (!input.renewedContracts.isEmpty()) {
renewer.load(null, JSON.serialize(input));
}
PageReference pageRef = new PageReference('/'+oppId);
pageRef.setRedirect(true);
return pageRef; //Returns to the opp page
} catch(Exception e) {
ApexPages.addMessages(e);
return null;
}
}
}