Search In This Blog

2020-12-23

VSCode: localhost 1717 no redirect when authorize an Org

Authorize an Org from VSCode.


Issue:

Callback URL localhost:1717 is not redirect.


reason:

proxy setting


Update the PATH Environment Variable (Microsoft Windows)

  1. From the desktop, right click the Computer icon.
  2. Choose Properties from the context menu.
  3. Click the Advanced system settings link.
  4. Click Environment Variables.
  5. Add HTTP_PROXY and HTTPS_PROXY variables

Set up proxy with username and password
HTTP_PROXY: http://USERNAME:PASSWORD@SERVER:PORT/
HTTPS_PROXY: https://USERNAME:PASSWORD@SERVER:PORT/

Set up proxy with domain, username and password
HTTP_PROXY: http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/
HTTPS_PROXY: https://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/

2020-10-30

Standard Save button prevent double click

Html source:
<form accept-charset="UTF-8" action="/a02/e" enctype="application/x-www-form-urlencoded" id="editPage" method="post" name="editPage" onsubmit="if (window.ffInAlert) { return false; }if (window.sfdcPage && window.sfdcPage.disableSaveButtons) { return window.sfdcPage.disableSaveButtons(); }" >

In main.js, two function named:
EditPage.prototype.disableSaveButtons ⇒ may used to disable save button after click
EditPage.prototype.enableSaveButtons ⇒ may used to active save button if error happened

Looks like salesforce is use form to submit data, and js to prevent doubleclick.

Prevent double submission of forms |二重送信防止

<!-- 送信ボタン2度押し防止策 -->
<script type="text/javascript">
var isSave = false;
function check(){
if (!isSave) {
isSave = true;
return true;
}
return false;
}

<apex:commandButton action="{!test}" value="Refresh" onclick="return check();"/>

https://developer.salesforce.com/forums?id=906F000000095yxIAA
http://salesforce.stackexchange.com/questions/7729/disable-commandbutton-after-first-click-to-prevent-double-submission

2020-07-03

Upload file/attachment | Apex Visualforce | Salesforce

template:
<apex:form>
    <apex:inputFile value="{!file}" />
<apex:commandbutton action="{!upload}" value="Upload" />
</apex:form>
Apex:
// file
public blob file {get;set;}
pubilc PageReference upload(){
    ContentVersion photofile = new ContentVersion();
    if(file != null){
        photofile.VersionData = file;
        photofile.Title='title';
        photofile.IsMajorVersion = false;
        photofile.PathOnClient='/title';
        insert photofile;
    }
    try{
        insert photofile;
    } catch(Exception Ex){
        System.debug('Ex==>'+Ex);
    }
    photofile = [select id, ContentDocumentId from ContentVersion WHERE Id =: photofile.Id];

    ContentDocumentLink cdl = new ContentDocumentLink();
    cdl.ContentDocumentId = photofile.ContentDocumentId;
    cdl.LinkedEntityId = [parentId]; 
    cdl.ShareType = 'V';
    cdl.Visibility = 'AllUsers';

    try{
        insert cdl;
    } catch(Exception Ex){
        System.debug('Ex==>'+Ex); 
    }
}
// Attachment
public blob file {get;set;}
pubilc PageReference upload(){
    try {
        if(file != null){
            attachment.body = file;
            attachment.name='title';
            attachment.OwnerId = UserInfo.getUserId();
            attachment.ParentId = [parentId];
            attachment.IsPrivate = true;

            insert attachment;
        }else{
            attachment = new Attachment();
        }
    } catch (Exception e) {
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'error'));
        return null;
    }
}

2020-05-15

Rule: trigger on the first day at 9 months later / 2 months earlier

9 month later  九ヶ月後
AND(
MONTH(DataOfferScheduledDate__c) <= 3 && TODAY() = DATE(YEAR(DataOfferScheduledDate__c), MONTH(DataOfferScheduledDate__c ) + 9, 1),
MONTH(DataOfferScheduledDate__c) > 3 && TODAY() = DATE(YEAR(DataOfferScheduledDate__c) + 1, MONTH(DataOfferScheduledDate__c) - 3, 1)
)
* Green number should sum up to 12


2 months earlier 二ヶ月前
AND(
MONTH(DataOfferScheduledDate__c) <= 2 && TODAY() = DATE(YEAR(DataOfferScheduledDate__c) - 1, MONTH(DataOfferScheduledDate__c ) + 10, 1),
MONTH(DataOfferScheduledDate__c) > 2 && TODAY() = DATE(YEAR(DataOfferScheduledDate__c), MONTH(DataOfferScheduledDate__c) - 2, 1)
)
* Change red number to any day you want

2020-04-01

Soap Api: Services url is different between Partner WSDL and Enterprise WSDL

Partner WSDL: services/Soap/u/
Enterprise WSDL: services/Soap/c/

Example:
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <n1:login xmlns:n1="urn:partner.soap.sforce.com">
      <n1:username>your_username</n1:username>
      <n1:password>your_password</n1:password>
    </n1:login>
  </env:Body>
</env:Envelope>

https://login.salesforce.com/services/Soap/u/48.0
 

2020-03-02

ERROR: VS Code deploy source to salesfores return 1

The situation
  • First time install VSC and salesforce extension pack
  • Success in web login auth to sfdc
  • Success in download source from sfdc
  • Failed in deploy

Fix by:
Upgrade the version of salesforce extension pack.
Terminal command: sfdx update

2020-01-15

getElement is not working in Lightning tag

SFDC defines it as Invalid DOM Access.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_dom.htm
<lightning:card aura:id="map" title="Current Boat Location">
    <div style="{!'width: ' + v.width + '; height: ' + v.height}">
        Please make a selection
    </div>
</lightning:card>

Because c:domLocker, below will be error.
var mapElement = component.find("map").getElement();

Change Dom as:
<lightning:card title="Current Boat Location">
    <div aura:id="map" style="{!'width: ' + v.width + '; height: ' + v.height}">
        Please make a selection
    </div>
</lightning:card>