function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ranadheer chRanadheer ch 

We previously using the detail page button to create a account in sap from salesforce account detail

How to provide an account id to external system like(3rd party) using javascript button on account detail page....any examples or code?....here i will use the Rest Api

When i click on that button of account detail page  then then third partys object like customer record should create...Using REst Api

Help me ...thanks in advance





 
Best Answer chosen by Ranadheer ch
RadnipRadnip
You just need to create a javascript button on the account object then when you create your REST call you can pass in the fields from the record by just typing (for example for account id):

{!Account.Id}

So if your REST API url was http://www.domain/API/updateAcc/<accountId>

then it would be:
http://www.domain/API/updateAcc/{!Account.Id}

You could either then have the external system call Salesforce via the API to collect the rest of the information it needs or you could pass everything in the REST call.
 

All Answers

RadnipRadnip
You just need to create a javascript button on the account object then when you create your REST call you can pass in the fields from the record by just typing (for example for account id):

{!Account.Id}

So if your REST API url was http://www.domain/API/updateAcc/<accountId>

then it would be:
http://www.domain/API/updateAcc/{!Account.Id}

You could either then have the external system call Salesforce via the API to collect the rest of the information it needs or you could pass everything in the REST call.
 
This was selected as the best answer
Ranadheer chRanadheer ch
Thanks Radnip.....

you mean that button will hold the accountID right?


And here is the Code is it right...

@RestResource(urlMapping='http://www.domain/API/updateAcc/{!Account.Id/*')
global with sharing class MyRestResource {

    @HttpDelete
    global static void doDelete() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account account = [SELECT Id FROM Account WHERE Id = :accountId];
        delete account;
    }
  
    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        return result;
    }
  
  @HttpPost
    global static String doPost(String name,
        String phone, String website) {
        Account account = new Account();
        account.Name = name;
        account.phone = phone;
        account.website = website;
        insert account;
        return account.Id;
    }
}


Please help me in this ...Am new to these services ...