• Troy Center
  • NEWBIE
  • 60 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 29
    Replies
I have these requirements. 
The BillingCode generated must be unique in the org. 
The BillingCode should whenever possible match the first three alpha letters of the Account Name, prefixed with 280. 

if Account name is A A Highlight, the Billing Code would be 280AAH, unless that was taken, 280AA? (? is single wildcard alpha char) is acceptable and if they are all taken, 280A?? would be acceptable. Of course in the end, Any available 280??? code is acceptable. 
Accept of course that there are only 17,576 available codes using this. That is acceptable too, exit and do nothing. 

AND Thanks. Think of this as a challenge. The Nested loops were flagged as potentially problematic. Is there another way to do this within these requirements? Thanks. Troy

Class and test Class below. Should work in a sandbox. You need to create the Billing_Code__c field on Account. Text, 6 characters. 
 
public with sharing class testbillingcode {
    public testbillingcode(list<Id> acctToCheck) {
        //Update the Accounts. 
        if(acctToCheck.size() > 0){
            list<Account> acctsList = [SELECT Id, Name, Billing_Code__c FROM Account WHERE Id IN :acctToCheck];
            List<Account> acctToUpdate = new List<Account>(); 
            if(acctsList.size() > 0){
                for(Account a : acctsList){
                    String strAccountName = a.Name; 
                    //Remove all Special Characters from Name String. 
                    strAccountName = strAccountName.replaceAll('(\\s+)', '');
                    strAccountName = strAccountName.replaceAll('[^a-zA-Z0-9\\s+]','');                    
                    String strAccountNameFirstCharacters = strAccountName.left(3).toUpperCase();

                    BillingCodeGenerator acctBillingCode = new BillingCodeGenerator(strAccountNameFirstCharacters);
                    String finalBillCode = acctBillingCode.getValue();
                    a.Billing_Code__c = finalBillCode;
                    a.Time_Code__c = '0'+finalBillCode+'01';
                    acctToUpdate.add(a);
                }
                update acctToUpdate;    
            }
        }            
    }

    public class BillingCodeGenerator {
        private final String value;
    
        public BillingCodeGenerator(String strAccountNameFirstCharacters) {
            this.value = this.generateValue(strAccountNameFirstCharacters);
        }
    
        public String getValue() {
            return this.value;
        }
    
        private String generateValue(String strAccountNameFirstCharacters) {
            
            Boolean FoundValidBillingCode = False; 
            String strAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

            //Select All Billing Codes from Salesforce where like 280
            List<Account> lstBillingCodeAccts = [SELECT Billing_Code__c FROM Account WHERE Billing_Code__c LIKE '280%'];
            List<String> lstBillingCodes = new List<String>();
                       

            for(Account a : lstBillingCodeAccts){
                lstBillingCodes.add(a.Billing_Code__c);
            }

            //Search for perfect match
            String strBillingCodePrefix = '280'+strAccountNameFirstCharacters;
            if(!lstBillingCodes.contains(strBillingCodePrefix)){
                //Did not find in SF. Use this Billing Code. Perfect Match found.
                FoundValidBillingCode = True;
                return strBillingCodePrefix;
            }
            if(FoundValidBillingCode == False){
               for(integer x = 0; x <= 25; x++){
                    strBillingCodePrefix = strBillingCodePrefix.left(5) +  strAlphabet.substring(x, x+1);
                    if(!lstBillingCodes.contains(strBillingCodePrefix) && !test.isRunningTest()){
                        FoundValidBillingCode = True;
                        return strBillingCodePrefix;
                    }
                }
            }
            if(FoundValidBillingCode == False){ 
                for(integer y = 0; y <= 25; y++){
                    for(integer x = 0; x <= 25; x++){
                        strBillingCodePrefix = strBillingCodePrefix.left(4) + strAlphabet.substring(x, x+1) + strAlphabet.substring(y, y+1);
                        if(!lstBillingCodes.contains(strBillingCodePrefix) && !test.isRunningTest()){
                            FoundValidBillingCode = True;
                            return strBillingCodePrefix; 
                        }
                    }
                }
            }
            if(FoundValidBillingCode == False) {
                for(integer z = 0; z <= 25; z++){
                    for(integer y = 0; y <= 25; y++){
                        for(integer x = 0; x <= 25; x++){
                            strBillingCodePrefix = '280' + strAlphabet.substring(x, x+1) + strAlphabet.substring(y, y+1) + strAlphabet.substring(z, z+1);
                            if(!lstBillingCodes.contains(strBillingCodePrefix)){
                                FoundValidBillingCode = True;
                                return strBillingCodePrefix;
                            }
                        }
                    } 
                }
            }
            return null;
        }
    }    
}


@istest
public class ContractTrigger_Tests {

    @istest
    public static void ContractTrigger_AcctBillCodeUpd_ZZZ_test() {		
        List<Id> lstAcctIds = new List<Id>(); 

        Account acctOne = new Account();
            acctOne.Name = 'Z Z-X-TestAccountAgain'; //AccountName has space in it. 
            acctOne.Type = 'Prospect';
            acctOne.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Standard').getRecordTypeId();
        insert acctOne;
        
        
        // Account acctTest1 = [SELECT Id, Billing_Code__c, Type, Name FROM Account WHERE id = :acctOne.Id];
        System.assertEquals(null, acctOne.Billing_Code__c, 'Account Billing Code s/b null. Actual:: '+acctOne.Billing_Code__c);
    
        lstAcctIds.add(acctOne.Id);
        testbillingcode sendTest; 
        sendTest = new testbillingcode(lstAcctIds);

        Account acctResult2 = [SELECT Id,Billing_Code__c,Type FROM Account WHERE id = :acctOne.Id];
        System.assertEquals(6, acctResult2.Billing_Code__c.length(), 'Account Billing_Code__c s/b 6 characters. Actual:: '+acctResult2.Billing_Code__c.length());

        List<Account> acctResult3 = [SELECT Id,Billing_Code__c,Type FROM Account WHERE Account.Billing_Code__c=:acctResult2.Billing_Code__c];
        System.assertEquals(1, acctResult3.size(), 'Only one account should have this Billing Code. Actual:: '+acctResult3.size());
    }

 

Test class:

/*
 * @description - This class is the test class for WOD_ProjectTriggerHandler,WOD_BusinessRules_ACK_DOC_Helper and WOD_ProjectDataService
 */
@isTest
public with sharing class WOD_ProjectTriggerHandlerTest {
    public WOD_ProjectTriggerHandlerTest() {
    }
    @testSetup
    public static void runTestSetup(){
        Test.startTest();
        WOD_DataFactoryTest.createAckBusinessRule();
        WOD_DataFactoryTest.createDocumentBusinessRule();
        twod_bm__Project__c project =  WOD_DataFactoryTest.createProject();
        project.twod_bm__Project_Status__c = 'Submitted';
        project.twod_bm__Is_Migrated_Data__c = true;
       // update project;
        
        // Adding Strategic Account also
        Account acc = WOD_DataFactoryTest.createAccount();
        acc.twod_bm__Strategic_Account__c = true;
        update acc;
        
        WOD_2__Inventory__c inventory =  WOD_DataFactoryTest.createInventory(project.Id);
        inventory.twod_bm__Inventory_Status__c = 'Pending Review';
        inventory.twod_bm__Guarantee_Issued__c = false;
        inventory.twod_bm__Strategic_Building__c = true;
        inventory.twod_bm__Strategic_AccountName__c = acc.id;
        inventory.twod_bm__Strategic_Price_Available__c = true;
        update inventory;
        
        WOD_2__Inventory__c inv = WOD_DataFactoryTest.createInventory(project.Id);
        inv.twod_bm__Guarantee_Issued__c = true;
        inv.twod_bm__Admin_Review__c = true;
        inv.twod_bm__Specification_Check__c = true;
        inv.twod_bm__Is_Building_Approved__c = true;
        
        update inv;
        
        twod_bm__Inspection__c ins = WOD_DataFactoryTest.createInspection(inv.id);
        ins.twod_bm__Type__c = 'Final Inspection';
        ins.twod_bm__Status__c = 'Pending Inspection';
        ins.twod_bm__Inspection_Rating__c = 'Conditionally accepted with Punchlist';
        update ins;
        
        twod_bm__Customer_Communication__c custComm = new twod_bm__Customer_Communication__c();
        custComm.twod_bm__Building__c = inventory.id;
        custComm.twod_bm__Status__c = 'Awaiting Response';
        //insert custComm;
        
        WOD_2__Warranty_Registration__c objwarranty= WOD_DataFactoryTest.createWarrantyRegistration(inventory.id);
        
        Test.stopTest();
    }
    @IsTest
    static void handlerMethods(){
        test.startTest();
        Account acc = new Account();
        acc.Name = 'Test Property Owner';
       // insert acc;

        twod_bm__Project__c proj = WOD_DataFactoryTest.createProject();
        WOD_2__Inventory__c inv = WOD_DataFactoryTest.createInventory(proj.Id);
        
        WOD_2__Warranty_Registration__c objwarranty= WOD_DataFactoryTest.createWarrantyRegistration(inv.id);
        Assembly__c ass = WOD_DataFactoryTest.createAssembly(inv.Id);
        WOD_DataFactoryTest.createAssemblydetail(ass.Id);

        proj.twod_bm__Property_Owner__c = acc.Id;
        proj.twod_bm__Submitted_Internally__c = true;
        proj.twod_bm__Project_Status__c = 'Submitted';
       // update proj;
        
        proj.twod_bm__General_Contractor__c = acc.Id;
       // update proj;
        WOD_ProjectTriggerHandler.createOpenItems(new List<twod_bm__Project__c>{proj});
        test.stopTest();
    }
    
    @IsTest
    static void handlerMethodsForDelete(){
        test.startTest();
        Account acc = new Account();
        acc.Name = 'Test Property Owner';
        //insert acc;

        twod_bm__Project__c proj = WOD_DataFactoryTest.createProject();
        WOD_2__Inventory__c inv = WOD_DataFactoryTest.createInventory(proj.Id);
        
        WOD_2__Warranty_Registration__c objwarranty= WOD_DataFactoryTest.createWarrantyRegistration(inv.id);
        Assembly__c ass = WOD_DataFactoryTest.createAssembly(inv.Id);
        WOD_DataFactoryTest.createAssemblydetail(ass.Id);
        proj.twod_bm__Property_Owner__c = acc.Id;
        proj.twod_bm__Submitted_Internally__c = true;
        proj.twod_bm__Project_Status__c = 'Submitted';
        //update proj;
        
        proj.twod_bm__General_Contractor__c = acc.Id;
       // update proj;
        delete proj;
        test.stopTest();
    }
}

Good day,

I have the following problem. I have created a few reports in my dev org and moved them to a newly created report folder. When I created my branch and retrieved the reports, only the folder was retrieved. There is no option to retrieve the created reports. Could you please give me advice how to do it? 

Hi Everyone!

Am new to slaesforce and Am trying to learn apex. 

Can anyone breakdown the following..

 

Schema.SObjectType.Event.getRecordTypeInfosByName().get(Label.RecordTypeName).getRecordTypeId();
 

Schema  --> is a class 
SObjectType--> Am guessing it is an inner class
Event--> I understand this can be any object api name but how does that translate to apex? how are we able to call an object name on class? is it because that the object name is a variable inside the inner class?
getRecordTypeInfosByName() --> I guess it is a method inside the inner class
get(Label.RecordTypeName) --> another method but how are we able to call method from a method? method1().method2()??
getRecordTypeId(); --> another method???

Am pretty new to oops(apex) and would like to know how they are internally structure for the way the calls are happeining in the above statement?
can any one explain please.

Thanks in advance!

Failed to save customLookup.cmp: Invalid definition for null:customLookUpController: ApexService.getType() return null with currentNamespace: c, namespace: null, name: customLookUpController: Source
Kill the process running on port 1717 or use a custom connected app and update OauthLocalPort in the sfdx-project.json file.
Hi All,

I am trying to authorize an org (Dev org not sandbox) from VS Code and I am in my Company network and default port Id 1717 wouldnt work for me. I have followed the below steps to create a Connected App and change port number in sfdx-project.json file. But still its taking me to old 1717 localhost even after changin the port number.

From Connected App..
User-added image

From VSCode project setup..

User-added image

I have also tried to put 443 in the redirected URL instead of 1717. But it doesnt work either.

Is there any mistake that I have done while setting up the Conncted App ? BTW, I am not using JWT AUthentication. Its just web based authentication. How else can I change the default port number ?

PS : I have used both "oauthLocalPort" : "443" and "oauthLocalPort" : 443. 
 
I properly installed CLI. In a command window, I enter:

sfdx force:auth:web:login -d -a DevHub

in order to log in to the trial Dev Hub that I created. The aforementioned command opens the Salesforce login page in the web browser, so I log in using my Developer Hub Trial Org credentials and click Allow. After that, web browser show me an error: "This site can't be reached. localhost took too long to respond".

This is the URL that Salesforce use after I authenticate in the browser: http://localhost:1717/OauthRedirect?code=aPrxbOND3gL_2LbSR7rKPdvD0XBVk2YpErl3pphY2f3xvZ1wf5SSPJByDleRLPMtzCQWnNGAdg%3D%3D&state=f2f8254fac23

I don't know what happen.

User-added image

User-added image

User-added image
Hello,
I have been going through this code for an hour now and cannot figure out why it is an "Illegal Assignment from String to List". Isn't an Email field a string?

The error is shown at the line I flagged, however the error might be somewhere else in my code too.
public class sendEmail {
    public String subject { get; set; }
    public String body { get; set; }
 
    private final <Object> WebInquiry;
 
    // Create a constructor that populates the Account object
    public sendEmail() {
        WebInquiry = [SELECT Email__c FROM <Object> WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    }
 
    public <Object> getWebInq() {
        return WebInquiry;
    }
 

    public PageReference send(){
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
 
String address;
        address = WebInquiry.Email__c;

****ERROR HERE****        String[] toAddresses = address;
 
        // Sets the paramaters of the email
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( body );
   
        // Sends the email
        Messaging.SendEmailResult [] r =
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  
        
        return null;
    }

}

Thanks for your help!
Ryan
Hi,
the challenge is as follows :

Create a camping component that contains a campingHeader and a campingList component.
1.The campingList component contains an ordered list of camping supplies that include Bug Spray, Bear Repellant, and Goat Food.
2.The campingHeader component contains an H1 heading style with a font size of 18 points and displays 'Camping List'.

so i made a lightening application named "camping.app" having code :

<aura:application >
    <br/><br/><br/>
    <c:campingHeader/>
    <c:campingList/>  
</aura:application>


where lightening component "campingHeader.cmp" having code :

<aura:component >
    <h1> Camping List </h1>
</aura:component>

for I have "campingHeader.css" having code :
.THIS {
}

h1.THIS {
    font-size: 18px;
}

and lightening component "campingList.cmp" having code :

<aura:component >
    <ol>
       <li>Bug Spray</li>
       <li>Bear Repellant</li>
       <li>Goat Food</li>      
    </ol>
</aura:component>

when i preview the application it is working nice; but when checking the challenge it says :
"Challenge Not yet complete... here's what's wrong: 
The 'camping' Lightning Component does not include either the campingHeader or campingList component."

please help me know where I m doing wrong. Thanx waiting for your reply
I want to initiate a Flow from a button on a Custom Object.  How do I capture the ID of that Custom Object record and be able to use it in the Flow?
I want to display current date  on a  field. i have writtened in formulae editor
 System.datetime.now
which results error and i have tried 
$System.OriginDateTime. but even getting wrong date.

I want to use record Type to limit trigger action. 

 

Now I use querey to get it my code liks below

string Id = [SELECT id from RecordType where Name ='Someone'].Id;

 

I also found this page, we could use method to get the Record Type Id to avoid the query.

I still can't understand it.

 

Is there some simple and easy wayt to get the ID only by Record Type's Name?

Hi All,

 

I've been trying to create some email templates and have come across a problem.  If I create them using the 'HTML(with letterhead)', the email is very narrow when its sent.  I was wondering if there is a way to change the width of the email?

 

I also created some using the 'Custom(without letterhead)' option.  When these email templates were used they utilised the entire width of the email unfortunately, I can't use this option as I need to allow users who have no knowledge of HTML to be able to edit the content of the email templates.

 

Can anyone offer any solutions?

 

Thanks in advance.

I am trying to run a query where I expect a single object to be returned under normal conditions. However, there is the possibility that invalid data will be submitted in which case the query will not return anything. Rather than handling this by getting a list, checking its size and then proceeding it seems sensible to simply try and return the single object and catch an exception if one arises using the following:

 

 

private static Licensable_Product_Release__c parseProductInformation( XmlStreamReader reader ) {

String identifier, version;

 

// Code to get identifier and version...

 

try {

return [SELECT Name FROM Licensable_Product_Release__c WHERE Licensable_Product__r.Identifier__c = :identifier AND Version__c = :version];

} catch( QueryException e ) {

System.debug( e.getMessage() );

}

 

return null; 

 

The problem is in my test case I intentionally feed it data so that the query will fail and at that point get:

 

 

Debug Log:

 

*** Beginning Test 1: XmlProductUpdatesRequestTransformer.static testMethod void test()

 

20091030045250.098:Class.XmlProductUpdatesRequestTransformer.parseProductInformation: line 63, column 12: SOQL query with 0 rows finished in 7 ms

System.QueryException: List has no rows for assignment to SObject

 

Unless I'm not understanding something here, it seems that my try/catch is being completely ignored. I've searched the forums and have found people getting this error without having a try/catch block but then it seems that adding a try/catch has solved the problem.

 

 

Any help greatly appreciated, thanks. 

 

Hi,  wondered if anyone could help determine why my Return URL is not working on a custom button.
 
"/a0E/e?CF00N20000001ZdDo_lkid={!Opportunity.Id}&CF00N20000001ZdDo={!Opportunity.Name}&retURL=https://emea.salesforce.com/{!Opportunity.Id}"
 
The above related to a new custom object related to the opportunity, on saving I would like it to return back to the opportunity.   I have tried lots of different options, even sending it to an external website to see what happens, but everytime it just takes me to the saved new record.
 
Is this not possible to do with custom objects, same code "retURL" works on custom event buttons.
 
Thanks for any assistance
 
I want to initiate a Flow from a button on a Custom Object.  How do I capture the ID of that Custom Object record and be able to use it in the Flow?