• enJoyLife
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
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;
Hello :)

I would like to write a POST method to create Contact. 
1) Check if email is already exist in SF and return SF Id to external service
2) If email doesn't exist create contact and return Id

@HttpPost
    global static Id createContactFromExternalCRM(String lastName, String firstName, String email, String phone) {
        
            Contact con = new Contact(
            LastName = lastName, 
            FirstName = firstName, 
            Email = email, 
            Phone = phone );
           
            insert con;
        return con.id;
        
    }
    
Thank you :)
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;
Hello :)

I would like to write a POST method to create Contact. 
1) Check if email is already exist in SF and return SF Id to external service
2) If email doesn't exist create contact and return Id

@HttpPost
    global static Id createContactFromExternalCRM(String lastName, String firstName, String email, String phone) {
        
            Contact con = new Contact(
            LastName = lastName, 
            FirstName = firstName, 
            Email = email, 
            Phone = phone );
           
            insert con;
        return con.id;
        
    }
    
Thank you :)