-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
77 lines (68 loc) · 2.87 KB
/
index.html
File metadata and controls
77 lines (68 loc) · 2.87 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Send Data To Salesforce</title>
<link rel="stylesheet" href="style.css">
<script>
let accessToken="";
let instanceurl="";
function authenticate(){
const url="https://login.salesforce.com/services/oauth2/authorize?"+
"response_type=token&"+
"client_id=3MVG9wt4IL4O5wvIrDAEJFQDJvOUtmP22fMq2Umv7UnSKECVwy3N.9BdK04ZAR9u97vuIQVK7RAVMagX9msla&"+
"redirect_uri=https://shri0900.github.io/Account-Form-Webpage/";
window.location.href=url; //used to extract current url from webpage
}
function pareseReturendHash(){
const hash=window.location.hash.substring(1);
//The window.location.hash returns a string that contains a # along with the
//fragment identifier of the URL. The fragment identifier of
//the URL starts with a # followed by an identifier that uniquely identifies a section in an HTML document.
const params=new URLSearchParams(hash);
accessToken=params.get("access_token");
instanceurl=params.get("instance_url");
}
function sendDataToSalesforce(){
const accountName=document.getElementById("accountName").value;
const accountIndustry=document.getElementById("accountIndustry").value;
if(accessToken && instanceurl){
fetch(instanceurl+"/services/data/v53.0/sobjects/Account",{
method:"POST",
headers:{
"Authorization": "Bearer " + accessToken,
"Content-Type":"application/json"
},
body:JSON.stringify({
Name:accountName,
Industry:accountIndustry
})
})
.then(response=>response.json())
.then(data=>{
console.log(data);
alert('Account Sent To Salesforce '+accountName)
})
.catch(error=>{
console.error("error Sending data to Salesforce",error);
});
}
else{
alert("not Authiticated With Salesforce")
}
}
window.onload=()=>{
pareseReturendHash();
}
</script>
</head>
<body>
<h1>Salesforce Account Form</h1>
<button onclick="authenticate()">Authenticate With Salesforce</button>
<br><br>
<input id="accountName" placeholder="Account Name Here" type="text">
<input id="accountIndustry" placeholder="Account Industry Here" type="text">
<button onclick="sendDataToSalesforce()">Create Account In Salesforce</button>
</body>
</html>