• Gonçalo Moreira
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello all,

I'm currently starting at SalesForce and came across a situation where I would like to have a validation rule to represent the Excel's PROPER() function, that is, capitalizing each word of a string.

I tried some solutions posted in these forums, including one that works but doesn't do the job for strings with more than 3 words.

That being said, I was looking to try another one posted (view code below):
 
IF(
FIND(" ", Name ,1)=0,
UPPER(LEFT(Name ,1))&MID(Name ,2,100),
IF(
FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))=0,
UPPER(LEFT(Name ,1))&
MID(Name ,2,FIND(" ",Name ,1)-1)&" "&
UPPER(MID(Name ,FIND(" ",Name ,1)+1,1))&
MID(Name ,FIND(" ",Name ,1)+2,100),
UPPER(LEFT(Name ,1))&
MID(Name ,2,FIND(" ",Name ,1)-1)&" "&
UPPER(MID(Name ,FIND(" ",Name ,1)+1,1))&
MID(Name ,FIND(" ",Name ,1)+2,FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))-1)&
UPPER(MID(Name ,FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))+FIND(" ",Name ,1)+1,1))&
MID(Name ,FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))+FIND(" ",Name ,1)+2,100)))

However, I'm getting the following error while trying to save:

 Error: Formula result is data type (Text), incompatible with expected data type (true or false).

Can anyone post advice on how to deal with this problem? I'm clueless about what I should modify so I could test it.

I also read that an Apex Trigger would do the job. I haven't tried that because like I said I'm still new to the platform and have been exploring it in the last couple days. 

Thanks in advance,

Best regards!
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" controller="lntg_DataTableClass" access="global" >
    <aura:attribute name="data" type="Object" default="{'sobjectType':'Account'}"/>
    <aura:attribute name="columns" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:card title="Account Editable Datatable">
        <lightning:datatable
                aura:id="accountDataTable"
                keyField="id"
                data="{!v.data}"
                columns="{!v.columns}"
                onsave ="{!c.onSave}"
                hideCheckboxColumn="false"/>
    </lightning:card>
</aura:component>


({
    doInit : function(component, event, helper) {
        var tableHeder=[
            {label: 'Name', fieldName: 'Name', editable:false, type: 'text'},
            {label: 'Industry', fieldName: 'Industry', type: 'text'},
            {label: 'Phone', fieldName: 'Phone', editable:true, type: 'Phone'},
            {label: 'Rating', fieldName: 'Rating', editable:true, type: 'text'}
        ];
        component.set("v.columns",tableHeder);
        helper.getdata(component,event,helper);
    },
    onSave:function(component,event,helper){
       
        helper.saveDataTable(component,event,helper);
    }
})



({
    getdata : function(component,event,helper) {
        var action=component.get("c.getAccounts");
        action.setCallback(this,function(response){
            var state=response.getState();
            if(state=="SUCCESS"){
                component.set("v.data",response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    saveDataTable:function(component,event,helper){
        var action=component.get("c.editRecordsupdated");
        /*var editRec =  component.find("accountDataTable").get("v.draftValues");
        alert('editRec..'+JSON.stringify(editRec));*/
        
        var draftValues = event.getParam('draftValues');
        var editRecordsLenght=draftValues.length;
        
        alert('draftValues..'+draftValues);
        action.setParams({
            'editReds':draftValues
        });
        action.setCallback(this,function(response){
            var state=response.getState();
            alert('state...'+state);
            if(state=="SUCCESS"){
                if(response.getReturnValue() === true){
                    alert('Record updated');
                    helper.showToast({
                        "title": "Record Update",
                        "type": "success",
                        "message": editRecordsLenght+" Account Records Updated"
                    });
                    helper.reloadDataTable();
                } else{ //if update got failed
                    helper.showToast({
                        "title": "Error!!",
                        "type": "error",
                        "message": "Error in update"
                    });
                }
            }else if (state === "INCOMPLETE") {
                // do something
            }
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                                        errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }
        });
        $A.enqueueAction(action);
    },
    /*
     * Show toast with provided params
     * */
    showToast : function(params){
        alert('showToast');
        var toastEvent = $A.get("e.force:showToast");
        if(toastEvent){
            toastEvent.setParams(params);
            toastEvent.fire();
        } else{
            alert(params.message);
        }
    },
    
    /*
     * reload data table
     * */
    reloadDataTable : function(){
        var refreshEvent = $A.get("e.force:refreshView");
        if(refreshEvent){
            refreshEvent.fire();
        }
    }
})

public class lntg_DataTableClass {
    @AuraEnabled
    public static List<Account> getAccounts(){
        return[select id,name,industry,phone,rating from Account limit 5];
    }
    @AuraEnabled
    public static Boolean editRecordsupdated(List<Account> editReds){
        try{
            System.debug('beforce editRecords..'+editReds);
            update editReds;
            System.debug('editRecords..'+editReds);
            return true;
        }catch(Exception e){
            System.debug('e.'+e);
            return false;
        }
    }

}

 
  • August 03, 2018
  • Like
  • 0
Hello all,

I'm currently starting at SalesForce and came across a situation where I would like to have a validation rule to represent the Excel's PROPER() function, that is, capitalizing each word of a string.

I tried some solutions posted in these forums, including one that works but doesn't do the job for strings with more than 3 words.

That being said, I was looking to try another one posted (view code below):
 
IF(
FIND(" ", Name ,1)=0,
UPPER(LEFT(Name ,1))&MID(Name ,2,100),
IF(
FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))=0,
UPPER(LEFT(Name ,1))&
MID(Name ,2,FIND(" ",Name ,1)-1)&" "&
UPPER(MID(Name ,FIND(" ",Name ,1)+1,1))&
MID(Name ,FIND(" ",Name ,1)+2,100),
UPPER(LEFT(Name ,1))&
MID(Name ,2,FIND(" ",Name ,1)-1)&" "&
UPPER(MID(Name ,FIND(" ",Name ,1)+1,1))&
MID(Name ,FIND(" ",Name ,1)+2,FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))-1)&
UPPER(MID(Name ,FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))+FIND(" ",Name ,1)+1,1))&
MID(Name ,FIND(" ",MID(Name ,FIND(" ",Name ,1)+1,LEN(Name )-FIND(" ",Name ,1)))+FIND(" ",Name ,1)+2,100)))

However, I'm getting the following error while trying to save:

 Error: Formula result is data type (Text), incompatible with expected data type (true or false).

Can anyone post advice on how to deal with this problem? I'm clueless about what I should modify so I could test it.

I also read that an Apex Trigger would do the job. I haven't tried that because like I said I'm still new to the platform and have been exploring it in the last couple days. 

Thanks in advance,

Best regards!