• אביב קסוטו
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 12
    Replies
I have an issue where i run an apex class and print some objects along the way to log using `System.debug()`.

my problem is that for some reason, the log rows are getting written, but the value of the objects is being "trimmed". the size that it writes and which gets trimmed isn't consistent (sometimes it prints a lot of content sometimes less) but it does not write the entirety of the objects values i choose to log.
It does this to both SObjects and json encoded strings, and my entire log size is just about 80KB so i know i'm not breaking some size limit.

I also checked my log levels and everything is set as it should (again my logs are being written just not "fully").

for example, I have the json string:

 `[{"sum":"2300","serial":"","repaymentDate":null,"payment":{"attributes":{"type":"Payment__c"},"Payment_Method__c":"Cash","checkdate__c":null,"Payment_Collected_Date__c":"2019-03-11"},"ownerId":null,"numOfPayments":null,"firstPaymentAmount":null,"digits":null,"cardType":null,"branch":null,"bank":"","account":""}`

But it gets written to the log file as:

    15:29:57:085 USER_DEBUG [69]|DEBUG|payments json: [{"sum":"2300","serial":"","repaymentDate":null,"payment":{"attributes":{"type":"Payment__c"},"Payment_Method__c":"Cash","checkdate__c":null,"Payment_Collected_Date__c":"2019-03-11"},"ownerId":null,"numOfPayments":null,"firstPaymentAmount":null,"digits":null,"cardType":null,"branch":nu

any ideas?
I'm trying to create some html elements as a reponse to a button click in my visualforce page, and i am using javascript remoting, but no matter what i do the page keeps refreshing after the button click.
my visualforce page:
 
<apex:page Controller="BpmIcountPayment">
<head>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css"/>
</head>
<body>
<script>

    function addProductRow(e) {
        e.preventDefault();
        var productId = $('select[id$=productsLov]').val();
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.BpmIcountPayment.getProductRowData}',
            productId,
        function(result, event) {
            if  (event.status) {
                productRowHtml = '<div id="p-' + result.Id + '">';
                productRowHtml += '<span>' + result.Description + '<span>';
                productRowHtml += '<button class="plusButton">+</button><input type="number">1</input><button class="minusButton">-</button>';
                if (result.Name == 'discount') {
                    productRowHtml += '<input classtype="number"></input><span>₪</span>';
                };
                productRowHtml += '<span>' + result.Price + '₪</span>';
                $('div[id$=productRows]').append(productRowHtml);
            } else if (event.type === 'exception') {
                console.log(event.message + '   ' + event.where);
            } else {
                console.log('else   ' + event.message);
            }
        }, {escape: true});
    }

</script>
</body>
<apex:form >
<div>
    <apex:selectList id="productsLov" value="{!productsTitle}" multiselect="false" size="1">
        <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
    </apex:selectList>
    <button id="addProductButton" onclick="addProductRow()" reRender="false">add product</button>
</div>
<div id="productsRows">
</div>
</apex:form>
</apex:page>

I even managed to print the result into the console, but it does so after refreshing the page.
my controller:

public class BpmIcountPayment{

private final Account account;

public String productsTitle {
  get { return 'products'; }
  set;
}

public List<Product2> productsList {
  get { return productsList; }
  set { productsList = value; }
}

public BpmIcountPayment() {
    account = [SELECT Id, Name, Site FROM Account
               WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}

public Account getAccount() {
    return account;
}

@RemoteAction
public static Product2 getProductRowData(string productId) {
    Product2 product = [SELECT Id, Name, Family, Price__c, Description 
                        FROM Product2 
                        WHERE Id = :productId];

    return product;
}

public List<SelectOption> getProductsLov() {
    List<SelectOption> products = new List<SelectOption>();
    productsList = [SELECT Id, Name, Family, Price__c, Description 
                    FROM Product2 
                    WHERE (Family = 'ShopProduct') 
                    OR (Family = 'CourseParent') 
                    OR (Family = 'SFCourseProgram')];

    for (Product2 currProduct : productsList) {
        products.add(new SelectOption(currProduct.Id, currProduct.Name));
    }

    return products;
}}

I am trying to display a selectList in a visualforce page using a custom controller i built.

I get an "List has no rows for assignment to SObject" error when trying to preview the page, but running the query in the developer console, returns the rows.

here is my page:
 

<apex:page Controller="BpmIcountPayment">
    <apex:param name="first_name" value="Account.FirstName"/>
    <apex:param name="last_name" value="Account.LastName"/>
    <apex:param name="id" value="Account.idnumber__c"/>
    <apex:param name="address" value="Account.Address"/>
    <apex:form >
        <apex:selectList value="{!productsTitle}" multiselect="false">
            <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
        </apex:selectList>
        </apex:form>
</apex:page>

and my controller:

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
      set;
    }
 
    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Id, Name, Family 
                                      FROM Product2 
                                      WHERE (Family = 'ShopProduct') 
                                      OR (Family = 'CourseParent') 
                                      OR (Family = 'SFCourseProgram')];

        system.debug(productsList);
        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));
        }

        return products;
    }
}

I am trying to display a select list from a custom controller, and i get a "Read only property 'productsTitle'" error when trying to save the visualforce page.

My custom controller:
 

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
    }
 
    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Name, Family 
                                      FROM Product2 
                                      WHERE (Family = 'ShopProduct') 
                                      OR (Family = 'CourseParent') 
                                      OR (Family = 'SFCourseProgram')];

        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));
        }

        return products;
    }
}

And my visualforce page:

<apex:page Controller="BpmIcountPayment">
    <apex:param name="first_name" value="Account.FirstName"/>
    <apex:param name="last_name" value="Account.LastName"/>
    <apex:param name="id" value="Account.idnumber__c"/>
    <apex:param name="address" value="Account.Address"/>
    <apex:form>
        <apex:selectList value="{!productsTitle}" multiselect="false">
            <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
        </apex:selectList>
    </apex:form>
</apex:page>

I am trying to retrieve data from salesforce using the REST api and CURL in PHP.

I perform the authentication request and recieve an 'instance_url' and 'access_token' but after performing a query request using those, i receive an "INVALID_SESSION_ID" error.

my authentication request code:

function get_sf_auth_data() {

	$post_data = array(
        'grant_type'    => 'password',
        'client_id'     => 'xxxxxxxxxxxxxxxxxxxxxx', //My client id (xxx... for this example)
        'client_secret' => '111111111111', // My client secret (111... for this example)
        'username'      => 'my_user_name',
        'password'      => 'my_user_password'
	);
	
	$headers = array(
    	'Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'
	);

	$curl = curl_init('https://login.salesforce.com/services/oauth2/token');
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);

	$response = curl_exec($curl);
	curl_close($curl);

    // Retrieve and parse response body
    $sf_access_data = json_decode($response, true);
    
    echo '*********' . $sf_response_data['instance_url'] . '********';
    echo '*********' . $sf_response_data['access_token'] . '********';

    return $sf_access_data;
}
My query request code:
function get_user_sfid($sf_access_data, $user_id_number){

	$sql = "SELECT Id, Name 
			FROM Account 
			WHERE ID__c = '$user_id_number'";

	$url = $sf_access_data['instance_url'] . '/services/data/v20.0/query/?q=' . urlencode($sql);

	$headers = array(
		'Authorization' => 'OAuth ' . $sf_access_data['access_token']
	);

	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_HEADER, false);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

	$json_response = curl_exec($curl);
	curl_close($curl);

	var_dump($json_response); // This prints out the response where i got the error

	$response = json_decode($json_response);

	return $response['id'];
}
The response to the query request as is:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
I have also tried using this guide (http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php) as refrence but it uses an "authorization_code" authentication and not a password one.

 

i have an sObject array that has the following objects:

[0]=>
  object(SObject)#1 (2) {
    ["type"]=>
    string(9) "Course__c"
    ["fields"]=>
    array(1) {
      ["Id__c"]=>
      string(3) "111"
    }
  }
  [1]=>
  object(SObject)#2 (2) {
    ["type"]=>
    string(9) "Course__c"
    ["fields"]=>
    array(1) {
      ["Id__c"]=>
      string(3) "222"
    }

Now, i have a string array of ids (for this example lets say it contains only "111"). What would be the best way to iterate over the object array and exatract the key of the object where id__c = "111"? in this example it would return "0".

Any help would be greatly appreciated.

I have an issue where i run an apex class and print some objects along the way to log using `System.debug()`.

my problem is that for some reason, the log rows are getting written, but the value of the objects is being "trimmed". the size that it writes and which gets trimmed isn't consistent (sometimes it prints a lot of content sometimes less) but it does not write the entirety of the objects values i choose to log.
It does this to both SObjects and json encoded strings, and my entire log size is just about 80KB so i know i'm not breaking some size limit.

I also checked my log levels and everything is set as it should (again my logs are being written just not "fully").

for example, I have the json string:

 `[{"sum":"2300","serial":"","repaymentDate":null,"payment":{"attributes":{"type":"Payment__c"},"Payment_Method__c":"Cash","checkdate__c":null,"Payment_Collected_Date__c":"2019-03-11"},"ownerId":null,"numOfPayments":null,"firstPaymentAmount":null,"digits":null,"cardType":null,"branch":null,"bank":"","account":""}`

But it gets written to the log file as:

    15:29:57:085 USER_DEBUG [69]|DEBUG|payments json: [{"sum":"2300","serial":"","repaymentDate":null,"payment":{"attributes":{"type":"Payment__c"},"Payment_Method__c":"Cash","checkdate__c":null,"Payment_Collected_Date__c":"2019-03-11"},"ownerId":null,"numOfPayments":null,"firstPaymentAmount":null,"digits":null,"cardType":null,"branch":nu

any ideas?
I'm trying to create some html elements as a reponse to a button click in my visualforce page, and i am using javascript remoting, but no matter what i do the page keeps refreshing after the button click.
my visualforce page:
 
<apex:page Controller="BpmIcountPayment">
<head>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css"/>
</head>
<body>
<script>

    function addProductRow(e) {
        e.preventDefault();
        var productId = $('select[id$=productsLov]').val();
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.BpmIcountPayment.getProductRowData}',
            productId,
        function(result, event) {
            if  (event.status) {
                productRowHtml = '<div id="p-' + result.Id + '">';
                productRowHtml += '<span>' + result.Description + '<span>';
                productRowHtml += '<button class="plusButton">+</button><input type="number">1</input><button class="minusButton">-</button>';
                if (result.Name == 'discount') {
                    productRowHtml += '<input classtype="number"></input><span>₪</span>';
                };
                productRowHtml += '<span>' + result.Price + '₪</span>';
                $('div[id$=productRows]').append(productRowHtml);
            } else if (event.type === 'exception') {
                console.log(event.message + '   ' + event.where);
            } else {
                console.log('else   ' + event.message);
            }
        }, {escape: true});
    }

</script>
</body>
<apex:form >
<div>
    <apex:selectList id="productsLov" value="{!productsTitle}" multiselect="false" size="1">
        <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
    </apex:selectList>
    <button id="addProductButton" onclick="addProductRow()" reRender="false">add product</button>
</div>
<div id="productsRows">
</div>
</apex:form>
</apex:page>

I even managed to print the result into the console, but it does so after refreshing the page.
my controller:

public class BpmIcountPayment{

private final Account account;

public String productsTitle {
  get { return 'products'; }
  set;
}

public List<Product2> productsList {
  get { return productsList; }
  set { productsList = value; }
}

public BpmIcountPayment() {
    account = [SELECT Id, Name, Site FROM Account
               WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}

public Account getAccount() {
    return account;
}

@RemoteAction
public static Product2 getProductRowData(string productId) {
    Product2 product = [SELECT Id, Name, Family, Price__c, Description 
                        FROM Product2 
                        WHERE Id = :productId];

    return product;
}

public List<SelectOption> getProductsLov() {
    List<SelectOption> products = new List<SelectOption>();
    productsList = [SELECT Id, Name, Family, Price__c, Description 
                    FROM Product2 
                    WHERE (Family = 'ShopProduct') 
                    OR (Family = 'CourseParent') 
                    OR (Family = 'SFCourseProgram')];

    for (Product2 currProduct : productsList) {
        products.add(new SelectOption(currProduct.Id, currProduct.Name));
    }

    return products;
}}

I am trying to display a selectList in a visualforce page using a custom controller i built.

I get an "List has no rows for assignment to SObject" error when trying to preview the page, but running the query in the developer console, returns the rows.

here is my page:
 

<apex:page Controller="BpmIcountPayment">
    <apex:param name="first_name" value="Account.FirstName"/>
    <apex:param name="last_name" value="Account.LastName"/>
    <apex:param name="id" value="Account.idnumber__c"/>
    <apex:param name="address" value="Account.Address"/>
    <apex:form >
        <apex:selectList value="{!productsTitle}" multiselect="false">
            <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
        </apex:selectList>
        </apex:form>
</apex:page>

and my controller:

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
      set;
    }
 
    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Id, Name, Family 
                                      FROM Product2 
                                      WHERE (Family = 'ShopProduct') 
                                      OR (Family = 'CourseParent') 
                                      OR (Family = 'SFCourseProgram')];

        system.debug(productsList);
        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));
        }

        return products;
    }
}

I am trying to display a select list from a custom controller, and i get a "Read only property 'productsTitle'" error when trying to save the visualforce page.

My custom controller:
 

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
    }
 
    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Name, Family 
                                      FROM Product2 
                                      WHERE (Family = 'ShopProduct') 
                                      OR (Family = 'CourseParent') 
                                      OR (Family = 'SFCourseProgram')];

        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));
        }

        return products;
    }
}

And my visualforce page:

<apex:page Controller="BpmIcountPayment">
    <apex:param name="first_name" value="Account.FirstName"/>
    <apex:param name="last_name" value="Account.LastName"/>
    <apex:param name="id" value="Account.idnumber__c"/>
    <apex:param name="address" value="Account.Address"/>
    <apex:form>
        <apex:selectList value="{!productsTitle}" multiselect="false">
            <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
        </apex:selectList>
    </apex:form>
</apex:page>

I am trying to retrieve data from salesforce using the REST api and CURL in PHP.

I perform the authentication request and recieve an 'instance_url' and 'access_token' but after performing a query request using those, i receive an "INVALID_SESSION_ID" error.

my authentication request code:

function get_sf_auth_data() {

	$post_data = array(
        'grant_type'    => 'password',
        'client_id'     => 'xxxxxxxxxxxxxxxxxxxxxx', //My client id (xxx... for this example)
        'client_secret' => '111111111111', // My client secret (111... for this example)
        'username'      => 'my_user_name',
        'password'      => 'my_user_password'
	);
	
	$headers = array(
    	'Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'
	);

	$curl = curl_init('https://login.salesforce.com/services/oauth2/token');
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);

	$response = curl_exec($curl);
	curl_close($curl);

    // Retrieve and parse response body
    $sf_access_data = json_decode($response, true);
    
    echo '*********' . $sf_response_data['instance_url'] . '********';
    echo '*********' . $sf_response_data['access_token'] . '********';

    return $sf_access_data;
}
My query request code:
function get_user_sfid($sf_access_data, $user_id_number){

	$sql = "SELECT Id, Name 
			FROM Account 
			WHERE ID__c = '$user_id_number'";

	$url = $sf_access_data['instance_url'] . '/services/data/v20.0/query/?q=' . urlencode($sql);

	$headers = array(
		'Authorization' => 'OAuth ' . $sf_access_data['access_token']
	);

	$curl = curl_init($url);
	curl_setopt($curl, CURLOPT_HEADER, false);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

	$json_response = curl_exec($curl);
	curl_close($curl);

	var_dump($json_response); // This prints out the response where i got the error

	$response = json_decode($json_response);

	return $response['id'];
}
The response to the query request as is:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
I have also tried using this guide (http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php) as refrence but it uses an "authorization_code" authentication and not a password one.

 

i have an sObject array that has the following objects:

[0]=>
  object(SObject)#1 (2) {
    ["type"]=>
    string(9) "Course__c"
    ["fields"]=>
    array(1) {
      ["Id__c"]=>
      string(3) "111"
    }
  }
  [1]=>
  object(SObject)#2 (2) {
    ["type"]=>
    string(9) "Course__c"
    ["fields"]=>
    array(1) {
      ["Id__c"]=>
      string(3) "222"
    }

Now, i have a string array of ids (for this example lets say it contains only "111"). What would be the best way to iterate over the object array and exatract the key of the object where id__c = "111"? in this example it would return "0".

Any help would be greatly appreciated.