• Quicksilvr
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi all

I'm currently working on a topic where I'm sending some survey links (hyperlinked to images) in Email Templates. These are connected to Cases and  I will be passing a few parameters such as the CaseNumber, CreatedDate, UserId of the sender etc in that URL.
I would also like to be able to send the DeveloperName of the Email Template that was used by the sender.

I can hard code this in every template (whether I use HTML (letterhead) or Custom HTML, but it adds maintenance overhead. Plus I want the power users to be able to edit / create templates on their own, hence I would like to use a merge field instead of hard coding it.


Thanks in advance for your input!
Hi guys,

I wrote a trigger to count the number of child Accounts in the hierarchy and store it in a custom field in the Parent Account.
Trigger works fine, except when I remove the parent-child mapping from one of the child Accounts ("deparent"). The count does not go down.
I'm pretty sure I'm overlooking something here. Any help appreciated.
Thank you !!
 
trigger countChildAcc on Account (after Insert, after Update) {
    Set<Id> Ids= new Set<Id>();
    List<Account> acclist = new List<Account>();
    Integer count = 0;
    
    if(Trigger.isInsert || Trigger.isUpdate){
        for(Account acc: Trigger.new){
            if(acc.ParentId!=null)
                Ids.add(acc.ParentId);
            acclist.add(acc);
        }
    }
    
    if(Trigger.isDelete){
        for(Account acc: Trigger.old){
            if(acc.ParentId!=null)
                Ids.add(acc.ParentId);
            acclist.add(acc);
        }
    }
        
    if(Ids.size()>0){
        List<Account> accChild = new List<Account>([SELECT Id,ParentId FROM Account WHERE ParentId IN: Ids]);
        List<Account> accParent = new List<Account>([SELECT Id,No_of_Child_Accounts__c FROM Account WHERE Id IN: Ids]);
        for(Account ac: accParent){
            count =0;
            for(Account acChild: accChild){
                if(acChild.ParentId == ac.Id)
                    count++;
            }
            ac.No_of_Child_Accounts__c = count;            
        }
        try{
            upsert accParent;
        }catch(DMLException ex){
            System.debug('Exception is '+ex);
        }
    }
}


Hi guys,

I'm looking for the best way generate a unique ID string from a record name.

Example:
Account Name: Universal Containers
Account Unique ID: UNI

UNI should be auto-populated, and has to be unique. If UNI is already associated with another record, then it should be UNV/UNC/UNL etc.

This ID only needs to be unique per territory / team. eg., UNI belonging to one territory, say the UK, is still unique from UNI belonging to the US. In this case I can't use the "Unique" checkbox in the formula field. I can probably overcome that by creating another formula field that copies the country code and the unique ID to check for duplicates.

When checking for duplicates, ideally it would follow this logic -

Account Name: Universal Containers
Country on User (Account Owner): UK

The trigger will populate "UKUNI" using
String ownerCountry = {!User.Country};
String accountName = {!Account.Name};

String UID = ownerCountry.substring(0,2) + accountName.substring(0,3);

Now this needs to be checked for being unique, and insert if it is. This is where I'm lost - if the ID is already taken, it should give me the next possible combo, letter 1,2,4 (UNV) or 1,2,5 (UNE) or 1,3,4 and so on.
Once I have this value, I can copy just the 3 letter code without the country code onto another field. This field will also be user editable, so in a sense, the system generated unique ID is a suggestion which the user can accept or override.


What would be the best approach to check for duplicates and generate the unique ID?

Thanks for you help!
Hi All,

I am new to salesforce lightning experience, I would like to create a custom clone button with selected fields only on opportunity, does anyone know to do that? Thanks. 
Hi guys,

I'm looking for the best way generate a unique ID string from a record name.

Example:
Account Name: Universal Containers
Account Unique ID: UNI

UNI should be auto-populated, and has to be unique. If UNI is already associated with another record, then it should be UNV/UNC/UNL etc.

This ID only needs to be unique per territory / team. eg., UNI belonging to one territory, say the UK, is still unique from UNI belonging to the US. In this case I can't use the "Unique" checkbox in the formula field. I can probably overcome that by creating another formula field that copies the country code and the unique ID to check for duplicates.

When checking for duplicates, ideally it would follow this logic -

Account Name: Universal Containers
Country on User (Account Owner): UK

The trigger will populate "UKUNI" using
String ownerCountry = {!User.Country};
String accountName = {!Account.Name};

String UID = ownerCountry.substring(0,2) + accountName.substring(0,3);

Now this needs to be checked for being unique, and insert if it is. This is where I'm lost - if the ID is already taken, it should give me the next possible combo, letter 1,2,4 (UNV) or 1,2,5 (UNE) or 1,3,4 and so on.
Once I have this value, I can copy just the 3 letter code without the country code onto another field. This field will also be user editable, so in a sense, the system generated unique ID is a suggestion which the user can accept or override.


What would be the best approach to check for duplicates and generate the unique ID?

Thanks for you help!