• dai tran 6
  • NEWBIE
  • 225 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 62
    Questions
  • 59
    Replies
I have a Custom object
I want after insert record 3 minutes, if Status=0 , This record will auto delete.
How can auto delete record after 3 minutes?
I want create a custom Login Page.
After login will go to a Force.com site.
This site using a PushTopic, so i must get Sesstion Id of User.
How can get Session Id from apex class by username & password?
I create a pushtopic : InvoiceStatementUpdates
URL:
https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/test_the_pushtopic_channel.htm
and run test at: https://workbench.developerforce.com/streaming.php

I had insert a record ok, but it not show message at streaming page:
{
  "channel": "/topic/InvoiceStatementUpdates",
  "data": {
    "event": {
      "type": "created",
      "createdDate": "2011-11-14T17:33:45.000+0000"
    },
    "sobject": {
      "Name": "INV-0004",
      "Id": "a00D0000008oLi8IAE",
      "Description__c": "Test invoice statement",
      "Status__c": "Open"
    }
  }
}

Why pushtopic not woking?
 
Code of Visualforce Page:
Show old contact infor of user and allow user edit (if not correct).   
                <tr><td>Sex:</td><td><apex:inputfield label="" value="{!contact.Salutation}" /></td></tr>
                <tr><td>First Name:</td><td><apex:inputfield label="" value="{!contact.FirstName}" /></td></tr>
                <tr><td>Last Name:*</td><td><apex:inputfield label="" value="{!contact.LastName}" /></td></tr>
                <tr><td>Email:*</td><td><apex:inputfield label="" value="{!contact.Email}" /></td></tr>          
                <tr><td>Phone:</td><td><apex:inputfield label="" value="{!contact.Phone}" /></td></tr>
                <tr><td>Street:</td><td><apex:inputfield label="" value="{!contact.MailingStreet}" /></td></tr>
                <tr><td>City:</td><td><apex:inputfield label="" value="{!contact.MailingCity}" /></td></tr>
                <tr><td>State:</td><td><apex:inputfield label="" value="{!contact.MailingState}" /></td></tr>
                <tr><td>Country:</td><td><apex:inputfield label="" value="{!contact.MailingCountry}" /></td></tr>
                <tr><td>PostalCode:</td><td><apex:inputfield label="" value="{!contact.MailingPostalCode}" />                </td></tr>

Result it display old information, but not allow input data.
Why inputfield not allow input data?
 
Visualforce page:
<apex:column > <apex:commandLink action="{!deleteItem}" reRender="frmList"  oncomplete="updateCarts();"> Remove</apex:commandLink></apex:column>
JAVASCRIPT:
<script>      
         function updateCarts(){  
            var listId = "{!ids}";
             alert(listId);
            
        } 
        </script>

Controller
public string ids { get; set;}
public CartsController()
  { 
   ids= 'ABCDEF';   
  }
  public void deleteItem()
  {
    ids='123456';
  }

Result : updateCarts had call before action and show alert : 'ABCDEF';

How can javascript after action complete?
Apex Rest API:
@HttpPost
        global static Integer checklogin(String email, String password ) {
              
                List<AccountUser__c>  listacc =  [SELECT email__c,Password__c,AccountId__r.type FROM AccountUser__c   WHERE Status__c=1 and email__c=:email and Password__c=:password   LIMIT 1];       
                if(listacc.size()>0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
           
        }
Call Rest Api from android:
url = "https://test-dev-ed.my.salesforce.com/services/apexrest/AccountUsers/"
    client = OkHttpClient()

    jsonIn = FormBody.Builder()
           .add("email","tranbadai1@@gmail.com")
           .add("password","123456")
           .build()

    request = Request.Builder()
            .post(jsonIn)
           .header("Authorization", "Bearer "+accesstoken)
           .addHeader("Content-Type", "application/json")
           .url(url)
           .build()

        response = client.newCall(request).execute()

response:
[{"errorCode":"UNSUPPORTED_MEDIA_TYPE","message":"Content-Type header specified in HTTP request is not supported: application/x-www-form-urlencoded"}]
How can call httpPost  of Rest API?

 
I try install Package DeveloperForce.Force 1.3.2  from nuget and try some code at: https://github.com/developerforce/Force.com-Toolkit-for-NET/blob/master/samples/SimpleConsole/Program.cs

But it occur error:
Severity	Code	Description	Project	File	Line	Suppression State
Error	NU1202	Package DeveloperForce.Force 1.3.2 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x64. Package DeveloperForce.Force 1.3.2 supports: net (.NETFramework,Version=v0.0)				
Error	NU1202	Package DeveloperForce.Force 1.3.2 is not compatible with monoandroid81 (MonoAndroid,Version=v8.1). Package DeveloperForce.Force 1.3.2 supports: net (.NETFramework,Version=v0.0)				
Error	NU1202	Package DeveloperForce.Force 1.3.2 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win. Package DeveloperForce.Force 1.3.2 supports: net (.NETFramework,Version=v0.0)				
Error	NU1202	Package DeveloperForce.Force 1.3.2 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0). Package DeveloperForce.Force 1.3.2 supports: net (.NETFramework,Version=v0.0)				
Error	NU1202	Package DeveloperForce.Force 1.3.2 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x86. Package DeveloperForce.Force 1.3.2 supports: net (.NETFramework,Version=v0.0)

    
How can connect salesforce from xamarin?
Apex calss:
@HttpPost
        global static Integer checklogin(String email, String password ) {
              
                List<AccountUser__c>  listacc =  [SELECT email__c,Password__c,AccountId__r.type FROM AccountUser__c   WHERE Status__c=1 and email__c=:email and Password__c=:password   LIMIT 1];       
                if(listacc.size()>0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
           
        }

I call Rest API from android:
                     url = "https://test-dev-ed.my.salesforce.com/services/apexrest/AccountUsers/"
                         client = OkHttpClient()

                         jsonIn = FormBody.Builder()
                                .add("email","tranbadai1@@gmail.com")
                                .add("password","123456")
                                .build()

                         request = Request.Builder()
                                 .post(jsonIn)
                                .header("Authorization", "Bearer "+accesstoken)
                                .addHeader("Content-Type", "application/json")
                                .url(url)
                                .build()
                     
                             response = client.newCall(request).execute()
Error:
[{"errorCode":"UNSUPPORTED_MEDIA_TYPE","message":"Content-Type header specified in HTTP request is not supported: application/x-www-form-urlencoded"}]

 
I access rest api from xamarin:
       HttpClient    client = new HttpClient();
       var RestUrl = "https://login.salesforce.com/services/oauth2/token";
            var uri = new Uri(string.Format(RestUrl, string.Empty));          
            UserInfo us = new UserInfo();
            us.grant_type = "password";
            us.client_id = "3MVG9YDQS5WtC11oHZF7qKDt4DyviHkb06byPkwfg_IqruHnLswqi6U23IXZUtGqGW4.ouwAaBxwxf.....";
            us.client_secret = "4085120398336......";
            us.username = "vnit12345@gmail.com";
            us.password = "123456dHfSkURI2khlRYpOoq7u.....";
            var json = JsonConvert.SerializeObject(us);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(uri, content);

**Result: **
_StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:_

In android, i using okhttp,it is ok. But In xamarin, i using httpclient, it can't.
How can access salesforce Rest API from xamarin?
 
I upload a image and use google vision api ocr it:
public blob file { get; set; }

public void uploadImage()
    {
String b64String = EncodingUtil.base64Encode(file);		
            Http http = new Http();	 
            HttpRequest  request = new HttpRequest();
            request.setMethod('POST');	     
            request.setHeader('Content-Length', '2000');
            request.setHeader('Content-Type', 'application/json');             
            request.setEndpoint('https://vision.googleapis.com/v1/images:annotate?key=AIzaSyDY2VbfNW9rIXOJs9O....');	        
                 
            request.setBody(b64String);	        
            HttpResponse response = http.send(request);	        
            imagetext= response.getBody();
           System.debug(imagetext);
}

Result:
00:01:19.61 (1062397547)|USER_DEBUG|[82]|DEBUG|{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Expected a value.\n/9j/4AAQSkZJRgABAQAA\n^",
    "status": "INVALID_ARGUMENT"
  }
}
How can call google vision api from apex?
Thank you.
 
I want get Text of Image after upload.
Has Einstein API support get Text from Image?
or 
Can  i call google vision api from apex?
I connect a Double and String:
​ <apex:column headerValue="Price" value="{!MapProducts[a]['Price__c'] & '$'}"/>

It show error:
Syntax error. Extra '&'​

Why can't connect String in visualforce page?
My controller:
public class LensPageController {
 public string username{get;set;}
    public List<Order> MyOrder {get;set;}
    public string err{get;set;}
    private final Order oderitem;
    public LensPageController(ApexPages.StandardController stdController)
    {
        this.oderitem = (Order)stdController.getRecord();
             Cookie ck=ApexPages.currentPage().getCookies().get('username');
             if(ck !=null)
             username=ck.getValue();           
        
            
    }
 
}

My visualforce page:
<apex:page  standardController="Order" extensions="LensPageController" showHeader="false" sidebar="false" >

But still can't select in page layout:
No Visualforce pages available
I create a profile: User License=Identity
I want allow this profile can read data of some Standard Object ( Orders, Products)
User-added image

How can add standard object to profile?
I install a App UPS from AppExchange:
I want allow a user can use it:
I create a new Profle [Nhanvien] and create a new user  use Profle [Nhanvien].
Setting Profle [Nhanvien]:
User-added image
But user still can't use app:
User-added image

How can allow a user use a app install?
I create a Public folder allow Guest upload image into salesforce.
How many is Limit memory of folder? 
 
I had try register  a free Analytics-enabled Developer Edition org.
at:https://trailhead.salesforce.com/trails/wave_analytics_einstein_discovery/modules/einstein_discovery_data_integration/units/bring_data_into_einstein_discovery
this version not exist Einstein Product Recommendations.
Have a developer  version of Commerce Cloud Einstein?
I have 2 Products: 
Product 1 -> Standard Price -> 200$
Product 2 -> Promotional price -> 100$

How can add 2  this Products into a Order?
insert order:
          Order od=new Order();
          od.AccountId=con.AccountId;
          //od.ContractId=hd.Id; 
          od.EffectiveDate=system.today();
          od.Status='Draft';
          insert od;

insert order item:
string searchquery='select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True  Order By UnitPrice ASC )  from Product2 where ProductCode in ('+SOQL_IDs+')'; 
              List<Product2>  MyProducts= Database.query(searchquery); 
              List<OrderItem> lsDetail=new List<OrderItem>();
              for(Integer i=0;i<MyProducts.size();i++)   
              {   if(MyProducts.get(i).PricebookEntries !=null && MyProducts.get(i).PricebookEntries.size()>0)
                  {
                      String code=MyProducts.get(i).ProductCode;
                      String sl=listCarts.get(code);
                      OrderItem ode=new OrderItem();
                      ode.OrderId=od.Id;
                      ode.Quantity=Double.valueOf(sl);
                      ode.PricebookEntryId=MyProducts.get(i).PricebookEntries.get(0).Id;
                      ode.UnitPrice=MyProducts.get(i).PricebookEntries.get(0).UnitPrice;
                      ode.Product2Id=MyProducts.get(i).Id;
                      lsDetail.Add(ode);
                      itotalMoney=itotalMoney+ ode.Quantity * ode.UnitPrice;
                  }
                 
              }
              
               insert lsDetail;

It occur error:
​Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Price Book Not Set on Order: []


 
I process insert to some tables:
public PageReference  checkoutPaypal()
    {
      try
      {
          List<AccountUser__c>  listacc =  [SELECT id,AccountId__c FROM AccountUser__c  WHERE  email__c=:email  LIMIT 1];
          AccountUser__c a=new AccountUser__c();
          Account acc=new Account();
          if(listacc.size()>0)
          {
              a=listacc.get(0);             
          }
          else
          {
              acc.Name=name;             
              insert acc;
              //save value ok    
             
              //           
              a.Name=name;
              a.AccountId__c=acc.Id;
              a.Email__c=email;
              a.Status__c=0;
              a.Password__c='0';
              insert a;            
           }
          
            
          Contact con=new Contact();
          con.LastName=name;
          con.Email=email;
          //con.Phone__c=phonenumber;
          con.AccountId=a.AccountId__c;
          insert con;
         
          //
          Contract hd=new Contract();
          hd.AccountId=a.AccountId__c;
          hd.StartDate=system.today();
          hd.ContractTerm=1;
          insert hd;
          
          Order od=new Order();
          od.AccountId=a.AccountId__c;
          od.ContractId=hd.Id; 
          od.EffectiveDate=system.today();
          insert od;
          Double itotalMoney=0;
          if(ids !='')
          {
            
              string searchquery='select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True  Order By UnitPrice ASC )  from Product2 where ProductCode in ('+SOQL_IDs+')'; 
              List<Product2>  MyProducts= Database.query(searchquery); 
              List<OrderItem> lsDetail=new List<OrderItem>();
              for(Integer i=0;i<MyProducts.size();i++)   
              {   
                  String code=MyProducts.get(i).ProductCode;
                  String sl=listCarts.get(code);
                  OrderItem ode=new OrderItem();
                  ode.OrderId=od.Id;
                  ode.Quantity=Double.valueOf(sl);
                  ode.UnitPrice=MyProducts.get(i).PricebookEntries.get(0).UnitPrice;
                  ode.Product2Id=MyProducts.get(i).Id;
                  lsDetail.Add(ode);
                  itotalMoney=itotalMoney+ ode.Quantity * ode.UnitPrice;
              }
              
               insert lsDetail;
          }
         
        
         Pagereference redirectedPage = New PageReference('/apex/payment?amount='+itotalMoney);  
         return redirectedPage;
      }
      catch(DmlException e)
      {
          err=e.getMessage();
      }
      
       return null;
      
    }
Current if function occur error, some process still insert data ok.
I want rollback all, if occur error/
How can rollback database in apex?
At trailhead description about Einstein Recommendations:
https://trailhead.salesforce.com/en/trails/get_smart_einstein/modules/get_smart_einstein_feat/units/get_smart_einstein_feat_tour
I want get list product Recommendations
How can use Einstein Recommendations?
In Setup ->Sanboxes: i click create sanbox:
User-added image
apex class: What is input?

I had try create a apex class , but it not allow:
User-added image
How can create a sanbox?
i using  a trial Lightning enterprise at: https://www.salesforce.com/ap/editions-pricing/service-cloud/
 
I want create a custom Login Page.
After login will go to a Force.com site.
This site using a PushTopic, so i must get Sesstion Id of User.
How can get Session Id from apex class by username & password?
I create a pushtopic : InvoiceStatementUpdates
URL:
https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/test_the_pushtopic_channel.htm
and run test at: https://workbench.developerforce.com/streaming.php

I had insert a record ok, but it not show message at streaming page:
{
  "channel": "/topic/InvoiceStatementUpdates",
  "data": {
    "event": {
      "type": "created",
      "createdDate": "2011-11-14T17:33:45.000+0000"
    },
    "sobject": {
      "Name": "INV-0004",
      "Id": "a00D0000008oLi8IAE",
      "Description__c": "Test invoice statement",
      "Status__c": "Open"
    }
  }
}

Why pushtopic not woking?
 
Code of Visualforce Page:
Show old contact infor of user and allow user edit (if not correct).   
                <tr><td>Sex:</td><td><apex:inputfield label="" value="{!contact.Salutation}" /></td></tr>
                <tr><td>First Name:</td><td><apex:inputfield label="" value="{!contact.FirstName}" /></td></tr>
                <tr><td>Last Name:*</td><td><apex:inputfield label="" value="{!contact.LastName}" /></td></tr>
                <tr><td>Email:*</td><td><apex:inputfield label="" value="{!contact.Email}" /></td></tr>          
                <tr><td>Phone:</td><td><apex:inputfield label="" value="{!contact.Phone}" /></td></tr>
                <tr><td>Street:</td><td><apex:inputfield label="" value="{!contact.MailingStreet}" /></td></tr>
                <tr><td>City:</td><td><apex:inputfield label="" value="{!contact.MailingCity}" /></td></tr>
                <tr><td>State:</td><td><apex:inputfield label="" value="{!contact.MailingState}" /></td></tr>
                <tr><td>Country:</td><td><apex:inputfield label="" value="{!contact.MailingCountry}" /></td></tr>
                <tr><td>PostalCode:</td><td><apex:inputfield label="" value="{!contact.MailingPostalCode}" />                </td></tr>

Result it display old information, but not allow input data.
Why inputfield not allow input data?
 
I connect a Double and String:
​ <apex:column headerValue="Price" value="{!MapProducts[a]['Price__c'] & '$'}"/>

It show error:
Syntax error. Extra '&'​

Why can't connect String in visualforce page?
I create a profile: User License=Identity
I want allow this profile can read data of some Standard Object ( Orders, Products)
User-added image

How can add standard object to profile?
I install a App UPS from AppExchange:
I want allow a user can use it:
I create a new Profle [Nhanvien] and create a new user  use Profle [Nhanvien].
Setting Profle [Nhanvien]:
User-added image
But user still can't use app:
User-added image

How can allow a user use a app install?
I create a Public folder allow Guest upload image into salesforce.
How many is Limit memory of folder? 
 
I have 2 Products: 
Product 1 -> Standard Price -> 200$
Product 2 -> Promotional price -> 100$

How can add 2  this Products into a Order?
insert order:
          Order od=new Order();
          od.AccountId=con.AccountId;
          //od.ContractId=hd.Id; 
          od.EffectiveDate=system.today();
          od.Status='Draft';
          insert od;

insert order item:
string searchquery='select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True  Order By UnitPrice ASC )  from Product2 where ProductCode in ('+SOQL_IDs+')'; 
              List<Product2>  MyProducts= Database.query(searchquery); 
              List<OrderItem> lsDetail=new List<OrderItem>();
              for(Integer i=0;i<MyProducts.size();i++)   
              {   if(MyProducts.get(i).PricebookEntries !=null && MyProducts.get(i).PricebookEntries.size()>0)
                  {
                      String code=MyProducts.get(i).ProductCode;
                      String sl=listCarts.get(code);
                      OrderItem ode=new OrderItem();
                      ode.OrderId=od.Id;
                      ode.Quantity=Double.valueOf(sl);
                      ode.PricebookEntryId=MyProducts.get(i).PricebookEntries.get(0).Id;
                      ode.UnitPrice=MyProducts.get(i).PricebookEntries.get(0).UnitPrice;
                      ode.Product2Id=MyProducts.get(i).Id;
                      lsDetail.Add(ode);
                      itotalMoney=itotalMoney+ ode.Quantity * ode.UnitPrice;
                  }
                 
              }
              
               insert lsDetail;

It occur error:
​Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Price Book Not Set on Order: []


 
TopController:
public string type {get;set;}
 public PageReference goPage2()
    {
            
       type='abc';
       PageReference p=new PageReference('/apex/page2');
       return p;
    
    }
public void getbyType()
{
 List<Product2> MyProducts=[Select Id From Product2 where type__c=:type];
}
Page1:
<apex:page controller="TopController" showHeader="false" sidebar="false" >
<apex:commandlink action="{!goPage2}" >

Page2:
<apex:page controller="TopController" showHeader="false" sidebar="false"  action="{!getbyType}">

How can store value of [type] to Page2 can use it?

 
Home page:
<apex:image styleClass="img"   value="{!URLFOR($Resource.MainImage, 'MainImage/womansun.jpg' )}"> 
        <apex:actionSupport event="onclick" action="{!goShopping}" >
            <apex:param assignTo="{!glasstype}" value="SUN" name="gtype" />
            <apex:param assignTo="{!sex}" value="Woman" name="gsex" />
        </apex:actionSupport>
    </apex:image>

Controller:
public PageReference goShopping()
    {
        System.debug(glasstype + sex);
        PageReference p=new PageReference('/apex/shopping');
        return p;   
    }

Log:
03:59:29.0 (12865001)|USER_DEBUG|[18]|DEBUG|nullnull

Why actionSupport can't send parameter?
<apex:form>
                    <apex:inputText id="txtName" value="{!name}" label="Input"/>
  </apex:form>
<script>
  var txtName = document.getElementById('txtName');
  txtName.value='abc';
</script>
Occur error: Uncaught TypeError: Cannot set property 'value' of null
How can set value to apex:inputText from javascript?
Visual Page:
<li><a href="" onclick="getProduct('{!fa.Family}'); return false;">{!fa.Family}</a></li>
<apex:actionFunction action="{!searchByFamily}" name="getProductFamily" >
           <apex:param name="family" value="" assignTo="{!family}" />
 </apex:actionFunction>
  <script>
  function getProduct(family)
         {
               getProductFamily(family);
         }
    </script>

Controller:
public string family { get;set;}
 public void searchByFamily(){ 
         System.debug(family);
            string searchquery='select ProductCode,Name,ImageName__c,(Select UnitPrice,Pricebook2.Name From PricebookEntries where IsActive=True)  from Product2 where Family=:family '; 
            MyProducts= Database.query(searchquery); 
     }

Log debug:
04:27:26.0 (32330563)|USER_DEBUG|[98]|DEBUG|null

Why actionFuntion can't send parameter?

Hi All,

 

Iam new to this OCR(Optical Character recognition). Right now we have a requirement to integrate OCR with Salesforce. Is there any APP out there which can do this?

 

Thanks