You need to sign in to do that
Don't have an account?
sreeja
this code is saved .. bt while creating the trigger on account it is showing an error with the below code
thanks
rest integration in salesforce
public class SendAccountUsingRestApi { String clientId='3MVG9676d8..z.hDcPLFoiqi2ctTtDy_x5RsHkuU9cjgz2WNbR6qyyrT8Oab.zpRK9whew.gYjriuYbDx41pikpc'; String clientsecret='608669815107085755889'; string username='ddddd@trailhead.com'; String password='TEaST@123'; String accesstoken_url='https://login.salesforce.com/services/oauth2/token'; String authurl='https://login.salesforce.com/services/oauth2/authorize'; public class deserializeResponse{ public String id; public String access_token; } public String ReturnAccessToken(SendAccountUsingRestApi Acc){ String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password; // String reqbody='{"grant_type":"password","client_id":clientId,"client_secret":clientSecret,"username":username,"password":password}'; Http h= new Http(); HttpRequest req= new HttpRequest(); req.setBody(reqbody); req.setMethod('POST'); req.setEndpoint('https://ap4.salesforce.com/services/oauth2/token'); //Change "ap4" in url to your Target Org Instance HttpResponse res=h.send(req); System.debug(res.getBody()+'###1203res'); deserializeResponse resp1=(deserializeResponse)JSON.deserialize(res.getBody(),deserializeResponse.class); System.debug(resp1+'###1203deserializeresponse'); return resp1.access_token; } @future(callout=true) public static void createAccount(String Accname){ SendAccountUsingRestApi acc1= new SendAccountUsingRestApi(); String accessToken=acc1.ReturnAccessToken(acc1); System.debug(accessToken+'###0012'); if(accessToken!=null){ String endPoint='https://ap5.salesforce.com/services/data/v32.0/sobjects/Account'; //Change "ap4" in url to your Target Org Instance String jsonstr='{"Name":"'+ Accname +'"}'; Http h2= new Http(); HttpRequest req2= new HttpRequest(); req2.setHeader('Authorization','Bearer ' + accessToken); req2.setHeader('Content-Type','application/json'); req2.setHeader('accept','application/json'); req2.setBody(jsonstr); req2.setMethod('POST'); req2.setEndpoint(endPoint); HttpResponse res2=h2.send(req2); System.debug(res2+'###1203createresp'); deserializeResponse deresp2=(deserializeResponse)System.JSON.deserialize(res2.getBody(),deserializeResponse.class); System.debug('###1203createdeser'+deresp2); } } }
this code is saved .. bt while creating the trigger on account it is showing an error with the below code
trigger SendAccount on Account (after insert) { for(Account a:Trigger.new){ SendAccountUsingRestApi.createAccount(a.name, a.Id); } }error is
Error Error: Compile Error: Method does not exist or incorrect signature: void createAccount(String, Id) from the type SendAccountUsingRestApi at line 3 column 33please solve this if possible
thanks
remove a.id , from trigger and try to save and , Change "ap4 or ap5" in into your Target Org Instance.. check weather it is ap5 or ap4
thanks and regards
karimulla syed
All Answers
trigger SendAccount on Account (after insert) {
for(Account a:Trigger.new){
SendAccountUsingRestApi.createAccount(a.name);
}
}
Please mark it best if it helps you. Thanks.
Regards,
Pankul
remove a.id , from trigger and try to save and , Change "ap4 or ap5" in into your Target Org Instance.. check weather it is ap5 or ap4
thanks and regards
karimulla syed