You need to sign in to do that
Don't have an account?
enJoyLife
@HTTPPUT to create Contract
Hi :)
I would like to write a PUT method to create contract :
My code below :
1) If an account exists in SF create a contract related with this account
2) If doesn't account exists in SF create a contract
Thank so much :)
@HttpPut
global static Contract createContractFomExternalCRM(Id accountId, Integer contractTerm, Date contractStart){
RestRequest accountRequest = RestContext.request;
String accountRequestURI = accountRequest.requestURI;
String accId = accountRequestURI.substring(accountRequestURI.lastIndexOf('/') + 1);
// Initializing contract to upsert
Account account = new Account();
Contract contract = new Contract();
// Assigning id to the contract if the contact id obtained from the URL is not empty
if(String.isNotEmpty(accountId)) {
System.debug('accid'+accId);
account.Id = accountId;
}
contract.StartDate = contractStart;
contract.ContractTerm = contractTerm;
// Upserting Contact
upsert contract;
// Returning the contact in the response
return contract;
I would like to write a PUT method to create contract :
My code below :
1) If an account exists in SF create a contract related with this account
2) If doesn't account exists in SF create a contract
Thank so much :)
@HttpPut
global static Contract createContractFomExternalCRM(Id accountId, Integer contractTerm, Date contractStart){
RestRequest accountRequest = RestContext.request;
String accountRequestURI = accountRequest.requestURI;
String accId = accountRequestURI.substring(accountRequestURI.lastIndexOf('/') + 1);
// Initializing contract to upsert
Account account = new Account();
Contract contract = new Contract();
// Assigning id to the contract if the contact id obtained from the URL is not empty
if(String.isNotEmpty(accountId)) {
System.debug('accid'+accId);
account.Id = accountId;
}
contract.StartDate = contractStart;
contract.ContractTerm = contractTerm;
// Upserting Contact
upsert contract;
// Returning the contact in the response
return contract;
Hi,
Please find the solution.
Please let me know it is working or not
Please mark it as the Best Answer if it Helps you
Thank You
Hi,
You can take references from the below code also.
Please let me know it is working or notPlease mark it as the Best Answer if it Helps you
Thank You
Thank you for your help :) It's not working but I found the solution
@HttpPut
global static Contract createContractFomExternalCRM(String accountName, Id accountId, Integer contractTerm, Date contractStart){
Account acc = [SELECT Id FROM Account WHERE Id = :accountId];
List<Account> accountList = [Select Id from Account where id=: acc.Id];
if(!accountList.isEmpty()){
Contract contract = new Contract(
StartDate = contractStart,
ContractTerm = contractTerm,
Accountid = accountList[0].id);
insert contract;
return contract;
} else{
Account account = new Account();
account.Name = accountName;
insert acc;
Contract contract = new Contract(
StartDate = contractStart,
ContractTerm = contractTerm,
Accountid = account.Id);
insert contract;
return contract;
}
}
Your code is almost the same as my code.
Please mark it as the Best
Thank You
The code before the else does't work .