• Sergio Mac Intosh
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 1
    Replies
Hi All,

I have a Wired Method like this:
 
recordId = '';
searchString;

@wire(searchUsers, {recordId: '$recordId', searchString: '$searchString'})

The method is working correctly, but the method is running everytime the recordId or the searchstring is changed. I would only like to run it when the searchstring is being changed & also not onload of the component. How can i manage this?

 
I have issues with a simple call to get records in Apex controller. I cant get the data in my LWC. The Apex Controller is being called correctly and the response is also correct.
 
import { LightningElement, wire } from 'lwc';

import LabelChooseTarget from '@salesforce/label/c.Choose_a_target';
import LabelCreateNewLabel from '@salesforce/label/c.Create_New';

import FIELD from '@salesforce/schema/Target_Configuration__c.Name';

import getAllConfigurations from '@salesforce/apex/ConfigurationController.getAllConfigurations';

const COLUMS = [
    {label : 'Name', fieldName : FIELD.fieldApiName, type: 'text'}
];


export default class ConfigurationSelector extends LightningElement {
    column = COLUMS

    label = {
        LabelChooseTarget
    };

    @wire(getAllConfigurations)
    configurations;

}
 
<template>
    <lightning-card  icon-name="custom:custom83" title={label.LabelChooseTarget}>

        <template if:true={configurations.data}>

        <lightning-datatable
            key-field="Id"
            data={configurations.data}
            colums={colums}>
        </lightning-datatable>

        </template>
    </lightning-card>
</template>



 
Hi,

There is no stylling for the submit button on my custom snapin component.
Any styling i add doesnt work neither. Now it looks like this:
User-added image
Anyone know how i can make this button look nice in a lightning style?
I more or less used the sample code in which the styling already didnt work:
https://developer.salesforce.com/docs/atlas.en-us.snapins_web_dev.meta/snapins_web_dev/snapins_web_lightning_components_prechat_sample_aura.htm


 
Hi, Can i publish multiple platform events using the REST API?
A single record works with this JSON:
{
"Order_number__c": "11111",
"Has_Shipped__c": true
}
How should the JSON look for multiple records?
Hi,

Can someone help me with my filereader?
It works perfect on google chrome but doesnt work on internet explorer because of the javascript function 'reader.readAsBinaryString(f);'
This function isn't supported in IE. Can someone help me to make this also work for IE?

Thanks in advance!
 
<apex:page docType="html-5.0" title="Upload Account Logo" standardController="Account" extensions="uploadAccountLogo" action="{!init}" sidebar="false" showHeader="false" >
    <style>
        .mypage {
            font-family: "ProximaNovaSoft-Regular", Calibri; 
            font-size: 110%;
            padding-top: 12px;
            width: 100%;
        }
        
        .mypage input[type=file] {
            width: 100%;
            height: 35px;
            -webkit-appearance: none;
            padding: 0 8px;
            margin: 4px 0;
            line-height: 21px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 3px;
            outline: none;
        }
        .mypage button {
            -webkit-appearance: button;
            border-radius: 3px;
            display: block;
            padding: 12px;
            margin: 4px 0;
            width: 100%;
            background: #eee;
            border: solid 1px #ccc;
        }
    </style>
    <apex:pageMessages id="messages"></apex:pageMessages>
    
    <apex:form >
    <apex:actionFunction name="showMessage" action="{!showMessage}" rerender="messages">
        <apex:param name="message" assignTo="{!message}" value="" />
        <apex:param name="messageType" assignTo="{!messageType}" value="" />
    </apex:actionFunction>
    </apex:form>
    
    <input type="hidden" id="accountId" name="accountId" value="{!getAccountId}"/>
    <input type="hidden" id="folderId" name="folderId" value="{!getDocFolderId}"/>
    
    <div class="mypage">
        <h3>Upload Account Logo</h3>
        <input type="file" id="file-input" name="file" accept="image/*"/>
        <button onclick="uploadFile()">UploadFile</button>
    </div>
    <script  src="/soap/ajax/38.0/connection.js" type="text/javascript"></script>
    <script  src="/soap/ajax/38.0/apex.js" type="text/javascript"></script>
    <script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
    sforce.connection.sessionId = '{!$Api.Session_ID}';
    
    function uploadFile(){        
        var accountId = document.getElementById('accountId').value;
		var folderId = document.getElementById('folderId').value;
    	var input = document.getElementById('file-input');

        var filesToUpload = input.files;
        
        if(filesToUpload[0] == 'undefined' || filesToUpload[0] == null){
            showMessage('File Not Found!','WARNING');
            return;
        }
        
        ///Get Account to later update the account logo id
        var queryAcc = "SELECT Id, Account_Logo_Id__c FROM Account WHERE Id = '{!getAccountId}' limit 1"; 
        var resultAcc = sforce.connection.query(queryAcc); 
        var recordsAcc = resultAcc.getArray("records");         
        var account = recordsAcc[0];
        
        ///Get existing document if exist
        var docName = 'accLogo_' + accountId;
        var queryDoc = "SELECT Id FROM Document WHERE Name = '"+ docName +"' limit 1";         
        var resultDoc = sforce.connection.query(queryDoc);
        var recordsDoc = resultDoc.getArray("records");
        var existingDocument = recordsDoc[0];
        
        for(var i = 0, f; f = filesToUpload[i]; i++){
            var reader = new FileReader();
            reader.file = f;

			reader.onerror = function(e){
            	switch(e.target.error.code){
                    case e.target.error.NOT_FOUND_ERR:
                        showMessage('File Not Found!','WARNING');
                        break;
                    case e.target.error.NOT_READABLE_ERR:
                        showMessage('File is not readable','WARNING');
                        break;
                    case e.target.error.ABORT_ERR:
                        break; 
                    default:
                        showMessage('An error occurred reading this file.','WARNING');
            	};
        	};     

        	reader.onabort = function(e){
                showMessage('File read cancelled','WARNING');
        	};

        	reader.onload = function(e){
                if(existingDocument == 'undefined' || existingDocument == null){
                    var doc = new sforce.SObject("Document");
                    doc.Name = 'accLogo_' + accountId ;
                    doc.Type = '.jpg';
                    doc.Description = 'Account Logo for account:' + accountId ;
                    doc.FolderId = folderId;
                    doc.Body = (new sforce.Base64Binary(e.target.result)).toString();
    
                    sforce.connection.create([doc],
                    {
                        onSuccess : function(result, source) 
                        {
                            if (result[0].getBoolean("success")) 
                            {
                                console.log("new document created with id " + result[0].id);
                                account.Account_Logo_Id__c = result[0].id;
                                var results = sforce.connection.update([account]);
                                showMessage('Logo uploaded succesfull', 'SUCCESS');
                            } 
                            else 
                            {
                                console.log("failed to create document " + result[0]);
                                showMessage('Insert failed: ' + result[0], 'ERROR');
                            }
                        }, 
                        onFailure : function(error, source) 
                        {
                        console.log("An error has occurred " + error);
                        showMessage('Insert failed: ' + error, 'ERROR');
                        }
                    });
                }else{
                    existingDocument.Body = (new sforce.Base64Binary(e.target.result)).toString();
                    
                    sforce.connection.update([existingDocument],
                    {
                        onSuccess : function(result, source) 
                        {
                            if (result[0].getBoolean("success")) 
                            {
                                console.log("new document updated with id " + result[0].id);
                                account.Account_Logo_Id__c = result[0].id;
                                var results = sforce.connection.update([account]);
                                showMessage('Logo uploaded succesfull', 'SUCCESS');
                            } 
                            else 
                            {
                                console.log("failed to update document " + result[0]);
                                showMessage('Update failed: ' + result[0], 'ERROR');
                            }
                        }, 
                        onFailure : function(error, source) 
                        {
                        console.log("An error has occurred " + error);
                        showMessage('Update failed: ' + error, 'ERROR');
                        }
                    });
                }
        	};

            reader.readAsBinaryString(f);
    	}
    }
    </script>
    
</apex:page>

 
Hi,

Within salesforce my vf page is working.
When i expose the same page using site.com i get the error: sf:INVALID_SESSION_ID

How can i solve this?

Thank you,

Sergio
Hi,

How can i activate the save button on visualforce page in SF1App with my javascript method?

Is it also possible to change the text on the cancel button? Instead of cancel i would like to call it 'back'.

Regards,

Sergio
My apexmessages aren't showed! Can someone help me out? 

Visualforce:
<apex:pageMessages></apex:pageMessages>
    
    <apex:form>
    <apex:actionFunction name="showSuccess" action="{!showSuccess}" rerender="messages">
        <apex:param name="message" assignTo="{!message}" value="" />
        <apex:param name="messageType" assignTo="{!messageType}" value="" />
    </apex:actionFunction>
    </apex:form>
Javascript:
showSuccess('Logo uploaded succesfull', 'SUCCESS');
Apex:
public string message{get; set;}
    public string messageType{get; set;}


 public void showSuccess(){
        if(messageType == 'SUCCESS'){
system.debug('TestMessage' + message);
            ApexPages.Message alertMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM,'TESTSUCCESS');
			ApexPages.addMessage(alertMsg); 
        	///ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, message));
        }else if(messageType == 'WARNING'){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, message));
        }else if(messageType == 'ERROR'){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, message));
        }

  	}
My system.debug is visible in the debug logs but the apex message doesn't appear.
Im using it in chatter (VF Chatter Action)

Thanks,

Sergio

 
I would like to get the detailed storage usage of the organization in apex.
We would like to store the detailed storage to see the data increasement overtime.

Using the REST API its only possible to get the overall storage usage.
We are looking for the object storage information.

Any idea's about working with this information might be usefull.

Thanks,

Sergio
I got this lightning method which calls the apex class 'getProducts'. Now i would like to call a apex class which needs an attribute.
How can i do this?
getMyObjects: function(cmp){
    var action = cmp.get("c.getProducts");
    action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
            cmp.set("v.myObjects", response.getReturnValue());
        }
    });
    $A.enqueueAction(action);
    }

 
Hi,

Can someone help me with my filereader?
It works perfect on google chrome but doesnt work on internet explorer because of the javascript function 'reader.readAsBinaryString(f);'
This function isn't supported in IE. Can someone help me to make this also work for IE?

Thanks in advance!
 
<apex:page docType="html-5.0" title="Upload Account Logo" standardController="Account" extensions="uploadAccountLogo" action="{!init}" sidebar="false" showHeader="false" >
    <style>
        .mypage {
            font-family: "ProximaNovaSoft-Regular", Calibri; 
            font-size: 110%;
            padding-top: 12px;
            width: 100%;
        }
        
        .mypage input[type=file] {
            width: 100%;
            height: 35px;
            -webkit-appearance: none;
            padding: 0 8px;
            margin: 4px 0;
            line-height: 21px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 3px;
            outline: none;
        }
        .mypage button {
            -webkit-appearance: button;
            border-radius: 3px;
            display: block;
            padding: 12px;
            margin: 4px 0;
            width: 100%;
            background: #eee;
            border: solid 1px #ccc;
        }
    </style>
    <apex:pageMessages id="messages"></apex:pageMessages>
    
    <apex:form >
    <apex:actionFunction name="showMessage" action="{!showMessage}" rerender="messages">
        <apex:param name="message" assignTo="{!message}" value="" />
        <apex:param name="messageType" assignTo="{!messageType}" value="" />
    </apex:actionFunction>
    </apex:form>
    
    <input type="hidden" id="accountId" name="accountId" value="{!getAccountId}"/>
    <input type="hidden" id="folderId" name="folderId" value="{!getDocFolderId}"/>
    
    <div class="mypage">
        <h3>Upload Account Logo</h3>
        <input type="file" id="file-input" name="file" accept="image/*"/>
        <button onclick="uploadFile()">UploadFile</button>
    </div>
    <script  src="/soap/ajax/38.0/connection.js" type="text/javascript"></script>
    <script  src="/soap/ajax/38.0/apex.js" type="text/javascript"></script>
    <script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
    sforce.connection.sessionId = '{!$Api.Session_ID}';
    
    function uploadFile(){        
        var accountId = document.getElementById('accountId').value;
		var folderId = document.getElementById('folderId').value;
    	var input = document.getElementById('file-input');

        var filesToUpload = input.files;
        
        if(filesToUpload[0] == 'undefined' || filesToUpload[0] == null){
            showMessage('File Not Found!','WARNING');
            return;
        }
        
        ///Get Account to later update the account logo id
        var queryAcc = "SELECT Id, Account_Logo_Id__c FROM Account WHERE Id = '{!getAccountId}' limit 1"; 
        var resultAcc = sforce.connection.query(queryAcc); 
        var recordsAcc = resultAcc.getArray("records");         
        var account = recordsAcc[0];
        
        ///Get existing document if exist
        var docName = 'accLogo_' + accountId;
        var queryDoc = "SELECT Id FROM Document WHERE Name = '"+ docName +"' limit 1";         
        var resultDoc = sforce.connection.query(queryDoc);
        var recordsDoc = resultDoc.getArray("records");
        var existingDocument = recordsDoc[0];
        
        for(var i = 0, f; f = filesToUpload[i]; i++){
            var reader = new FileReader();
            reader.file = f;

			reader.onerror = function(e){
            	switch(e.target.error.code){
                    case e.target.error.NOT_FOUND_ERR:
                        showMessage('File Not Found!','WARNING');
                        break;
                    case e.target.error.NOT_READABLE_ERR:
                        showMessage('File is not readable','WARNING');
                        break;
                    case e.target.error.ABORT_ERR:
                        break; 
                    default:
                        showMessage('An error occurred reading this file.','WARNING');
            	};
        	};     

        	reader.onabort = function(e){
                showMessage('File read cancelled','WARNING');
        	};

        	reader.onload = function(e){
                if(existingDocument == 'undefined' || existingDocument == null){
                    var doc = new sforce.SObject("Document");
                    doc.Name = 'accLogo_' + accountId ;
                    doc.Type = '.jpg';
                    doc.Description = 'Account Logo for account:' + accountId ;
                    doc.FolderId = folderId;
                    doc.Body = (new sforce.Base64Binary(e.target.result)).toString();
    
                    sforce.connection.create([doc],
                    {
                        onSuccess : function(result, source) 
                        {
                            if (result[0].getBoolean("success")) 
                            {
                                console.log("new document created with id " + result[0].id);
                                account.Account_Logo_Id__c = result[0].id;
                                var results = sforce.connection.update([account]);
                                showMessage('Logo uploaded succesfull', 'SUCCESS');
                            } 
                            else 
                            {
                                console.log("failed to create document " + result[0]);
                                showMessage('Insert failed: ' + result[0], 'ERROR');
                            }
                        }, 
                        onFailure : function(error, source) 
                        {
                        console.log("An error has occurred " + error);
                        showMessage('Insert failed: ' + error, 'ERROR');
                        }
                    });
                }else{
                    existingDocument.Body = (new sforce.Base64Binary(e.target.result)).toString();
                    
                    sforce.connection.update([existingDocument],
                    {
                        onSuccess : function(result, source) 
                        {
                            if (result[0].getBoolean("success")) 
                            {
                                console.log("new document updated with id " + result[0].id);
                                account.Account_Logo_Id__c = result[0].id;
                                var results = sforce.connection.update([account]);
                                showMessage('Logo uploaded succesfull', 'SUCCESS');
                            } 
                            else 
                            {
                                console.log("failed to update document " + result[0]);
                                showMessage('Update failed: ' + result[0], 'ERROR');
                            }
                        }, 
                        onFailure : function(error, source) 
                        {
                        console.log("An error has occurred " + error);
                        showMessage('Update failed: ' + error, 'ERROR');
                        }
                    });
                }
        	};

            reader.readAsBinaryString(f);
    	}
    }
    </script>
    
</apex:page>