i am trying to develop visualforce page. i want to make a call. iwrite a code
public class SampleClass{
String account = 'XXXXXXXXXXXXXXXXXXX';
String token = 'YYYYYYYYYYYYYYYYYY';
public PageReference hello(){
TwilioRestClient client = new TwilioRestClient(account, token);
Map<String,String> params = new Map<String,String> {
'To' => '+919953938584',
'From' => '+919910728457',
'Url' => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
};
TwilioCall call = client.getAccount().getCalls().create(params);
return null ;
}
}
and visualforce page
<apex:page controller="SampleClass">
<apex:form >
<apex:commandButton action="{!hello}" value="Make a Call"/>
</apex:form>
</apex:page>
both the numbers are verified so call is going and a music is playing.now i want that when the user click make a call button then he can talk to the dialled phone number.means his voice went to the number which is dialled and he can hear that voice.in other way that user can dial a phone number and talk to a person using only browser .is this possible .Please guideline.
I think you want to have one leg of you call from the Browser? So Browser to Phone handset? If this is the case you can use Twilio Client.
There are some quick starts on the Twilio site that should get you started.
Hope this helps!
Related
I just started learning Apex recently, and there's still a lot of topics that are hard for me to navigate at this time. I've searched everywhere for a solution that works, but I still haven't been able to figure it out.
I've created a button on my Salesforce org that renders a PDF from a visualforce page, and attaches it to the record as a File. This is to be used with Docusign later on to capture signatures for contracts. The problem is that, when using merge fields in the VF page, they either do not show at all, or I get this exception: "sObject row was retrieved via SOQL without querying the requested field".
Now, the exception explicitly says that I need to query the fields, and this is what I've found I need to do to make this work, but I have not been able to figure out how to do this properly. I've tried running a query in several places in my controller extension to no avail (I am using a standardController that SF created for my custom object).
Here's my extension's code:
public class attachPDFToQuote {
public final i360__Quote__c q {get; set;} //Quote object
//constructor
public attachPDFToQuote (ApexPages.StandardController stdController) {
q = (i360__Quote__c)stdController.getRecord();
/* for(i360__Quote__c query:[SELECT Id, Correspondence_Name__c, Name FROM i360__Quote__c WHERE Id=: q.Id]){
System.debug(i360__Quote__c.Correspondence_Name__c);
}*/
}
public PageReference attachPDF() {
/* for(i360__Quote__c query:[SELECT Id, Correspondence_Name__c, Name FROM i360__Quote__c WHERE Id=: q.Id]){
System.debug(i360__Quote__c.Correspondence_Name__c);
}*/
//generate and attach the PDF document
PageReference pdfPage = Page.ProjectAgreement;
Blob pdfBlob; //create a blob for the PDF content
if (!Test.isRunningTest()) { //if we are not in testing context
pdfBlob = pdfPage.getContent(); //generate the pdf blob
} else { //otherwise, we are in testing context. Create the blob manually.
pdfBlob = Blob.valueOf('PDF');
}
ContentVersion cvAttach = new ContentVersion(ContentLocation= 'S');
cvAttach.PathOnClient= 'Project Agreement.pdf';
cvAttach.Title= 'Project Agreement';
cvAttach.VersionData= pdfBlob;
insert cvAttach;
Id conDoc = [SELECT ContentDocumentID FROM ContentVersion WHERE Id=: cvAttach.Id].ContentDocumentId;
ContentDocumentLink ConDocLink = new COntentDocumentLink();
conDocLink.LinkedEntityId= q.Id;
conDocLink.ContentDocumentId= conDoc;
conDocLink.ShareType= 'V';
insert conDocLink;
//redirect the user
PageReference pageWhereWeWantToGo = new ApexPages.StandardController(q).view(); //redirect the User back to the Quote detail page
pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
return pageWhereWeWantToGo; //send the User on their way
}
}
I kept the commented code where I try to query the object fields so they show in VF. I also tried a couple of different ways, but nothing seems to work. Please let me know if I need to add anything else.
Thank you!
You didn't post your Visualforce page's code.
Even if it's same page (if your apex class is used in ProjectAgreement VF as <apex:page standardController="i360__Quote__c" extensions="attachPDFToQuote" - the act of grabbing a PDF version of the page counts as callout, a separate http traffic to fresh instance of the page so to speak.
So I suspect you need something like
PageReference pdfPage = Page.ProjectAgreement;
pdfPage.getParameters().put('id', q.Id);
Blob = pdfPage.getContent();
If that works... next step would be to look at your VF code.
If the page has merge fields such as {!i360__Quote__c.Name}, {!i360__Quote__c.Correspondence_Name__c} then magic should happen. Salesforce should figure out which fields are needed by looking at your VF page and silently query them for you. So you wouldn't even need the query in your constructor, you could just save stdController.getId() to class variable and then use that id in pdfPage.getParameters().set(...)
But if your VF page has references to {!quote.Correspondence_Name__c} then you need to keep the explicit query in there.
We have a web application that users log into and consume our products. From this application, we'd like to have a form that users can submit to create cases in our Salesforce instance. I'm looking for a REST API endpoint that I can POST the new case information to, which will then create a new case record in Salesforce. I'm a little confused on the right way to approach this based on the Salesforce docs (Apex, Lightning Platform, Force.com, etc.). Has anyone implemented this or can share the right approach?
Easiest way to would be to create a force.com site, which is essentially a visualforce page. Your page can then use a controller to read values and create Cases.
For e.g. this visualforce page updates a custom object record by using id passed in url:
<apex:page controller="MyService"></apex:page>
#RestResource(urlMapping='/myservice')
global class MyService {
#HttpGet
global static void doGet() {
RestContext.response.addHeader('Content-Type', 'text/plain');
String id = RestContext.request.params.get('id');
abc__c veh = [select name, abc__c from abc__c where id =:id];
if(veh!=null)
{
veh.abc__c = true;
try {
update veh;
} catch (DMLException e) {
RestContext.response.responseBody = Blob.valueOf('DML ERROR');
}
RestContext.response.responseBody = Blob.valueOf('OK');
}
else
RestContext.response.responseBody = Blob.valueOf('FAIL');
}
}
I created a VF page and RemoteAction there is no system.debug or console.log anywhere in apex class or vf page respectively, as a result of which in Chrome developer tools -> console log there is not output but surprisingly in Network tab if you select apexremote you get to see the data returned from the query even the encrypted fields in the object.
If you see the code below, credit_card__c field is encrypted, and I am not even exposing it in my VF, still in chrome developer tools network tab I see the entire data.
How can I stop any log in my network tab of chrome developer tools ?
global class AccountRemoteService {
public String accountName { get; set; }
public static Account account { get; set; }
global AccountRemoteService(){}
#RemoteAction
global static Account getAccount(String accountName)
{
account = [SELECT id, name, credit_card__c FROM Account WHERE name = :accountName ];
return account;
}
}
VF Page
<apex:page controller="AccountRemoteService">
<script type="text/javascript">
function getRemoteAccount()
{
//get the values of input text and place into the variable.
var paramAccountName = document.getElementById('accName').value;
AccountRemoteService.getAccount( paramAccountName,
function(result, event)
{
alert('event.status==>'+event.status);
alert('event.type === '+event.type);
alert('event.message ==>'+event.message);
if (event.status)
{
// demonstrates how to get ID for HTML and Visualforce tags
document.getElementById("{!$Component.theBlock.thePageBlockSection.accountId.Id}").innerHTML = result.Id;
document.getElementById("{!$Component.theBlock.thePageBlockSection.accountName.Nam}").innerHTML = result.Name;
}
else if (event.type === 'exception')
{
document.getElementById("errors-js").innerHTML = event.message;
} else
{
document.getElementById("errors-js").innerHTML = 'No Records Found..';
}
}, {escape:true});
}
</script>
Account Name :<input id="accName" type="text" />
<button onclick="getRemoteAccount()">Get Account</button>
<div id="errors-js"> </div>
<apex:pageBlock id="theBlock">
<apex:pageBlockSection id="thePageBlockSection" columns="2">
<apex:pageBlockSectionItem id="accountId">
<apex:outputText id="Id"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id="accountName" >
<apex:outputText id="Nam" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
There are a lot of things here that you are doing that should probably be done a different way, that I would just mention as an aside.
You are querying account by name not by a unique value which can lead to possibly more than one account in the result or no results and you are returning to a single Account record. In either of those cases an exception would be thrown. Use a List instead.
If you are going to use remote action you should perform an access to ensure the user has access to the field you are returning so as not to expose data unintentionally
I would recommend that you use the platform safeguards in visualforce to enforce field encryption. Use the to reference the object from your controller, you already have the account accessible to the visualforce page it's public with get; set;
In short there are certain situation where encrypted fields are not masked, I would recommend using the platform feature that helps make this easier. See here for more details.
You can achieve the same or a similar effect using actionRegion commandButtons and partial page re-rendering.
I have a basic question about salesforce session, i want to logout my users automatically when they close the browser window.
Thanks for your help.
This is an old thread but I thought I would go ahead and share my work around...
Add a controller to your site home page, and in the init action, redirect to secure page, if it is not already a secure page.
public PageReference init() {
String currentURL = Site.getCurrentSiteUrl();
if (!startsWith(currentUrl, 'https://')) {
return redirect(currentURL.replace('http://', 'https://'));
}
return null;
}
I have an application added to several fan pages.
Ideally, the application should work custom depending on the referring page.
How can I detect which page referred to the app.
Developing a Facebook Iframe app, Using PHP.
(Question posted on Facebook's dev forum as well:
http://forum.developers.facebook.net/viewtopic.php?id=108409)
Thx,
Oren.
As explained in the Page Tab Tutorial
When a user selects your Page Tab, you will received the signed_request parameter with one additional parameter, page. This parameter contains a JSON object with an id (the page id of the current page), admin (if the user is a admin of the page), and liked (if the user has liked the page). As with a Canvas Page, you will not receive all the user information accessible to your app in the signed_request until the user authorizes your app.
With the http referer, you will have the the Facebook proxy url.
In your case, I think you have to use the id of the page (passed in the signed request).
The following PHP snippet will output the signed_request received on the page tab. You will find the page ID needed in your case.
<?php
$appsecret = 'Your App Secret';
$signed_request = $_REQUEST['signed_request'];
$request = $_REQUEST;
$signed_request = parse_signed_request($signed_request, $appsecret);
print_r($signed_request);
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
?>
Using the new php-sdk, there is a quicker way to find out the referring page. $facebook->getSignedRequest() will return an array with the signed request, authorization token, page and user basic info.