• Pavlo Shchur
  • NEWBIE
  • 114 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 2
    Questions
  • 15
    Replies
public class ScannedBusinessCardRESTResource {
    
    public static void doGet() {
        
        RestContext.response.addHeader('Content-Type', 'application/json');
        
        String userId = RestContext.request.params.get('creatorId'); 
        String status = RestContext.request.params.get('status');
        String cardId = RestContext.request.params.get('id');
        
        if(userId != null && status != null && cardId == null) {
            
            RestContext.response.responseBody = 
                Blob.valueOf(JSON.serialize( 
                    new DTOScannedBusinessCard.CardsList( ScannedBusinessCardDAO.getBusinessCardByCreatedByIdAndStatus(userId, status) )));
        }
        
        else if(cardId == null){
            
            RestContext.response.responseBody 
                = Blob.valueOf(JSON.serialize( new DTOScannedBusinessCard.StatusMessage( 'errorMessage_string', '400' ) ));
            
        } 
        
        
        if(userId == null && status == null && cardId != null) {
            
            RestContext.response.responseBody = 
                Blob.valueOf(JSON.serialize( 
                    new DTOScannedBusinessCard.CardsList_2( ScannedBusinessCardDAO.getCardByCardId(cardId))));
        }
        
        else if(userId == null && status == null){
            
            RestContext.response.responseBody 
                = Blob.valueOf(JSON.serialize( new DTOScannedBusinessCard.StatusMessage( 'errorMessage_string', '400' ) ));
            
        }
        
    }
    
    public static void doPost() {
        
        System.debug('doPost()');
        
        Scanned_Business_Cards__c result = new Scanned_Business_Cards__c();
        
        RestRequest req = RestContext.request;
        
        RestResponse res = RestContext.response;
        
        ScannedBusinessCardDTO data = (ScannedBusinessCardDTO) JSON.deserialize(
            
            RestContext.request.requestBody.toString(),
            ScannedBusinessCardDTO.class
            
        );
        
        
        if(data.cardId != null) {
                        
            result = [SELECT Salutation__c, 
                      First_Name__c, Last_Name__c, 
                      Full_Name__c, Account_Name__c, 
                      Title__c, Phone__c, 
                      Mobile__c, Fax__c, 
                      Email__c, Website__c, 
                      Street1__c, Street2__c, 
                      City__c, State_Country__c, 
                      Country__c, Postcode__c, Address__c 
                      FROM Scanned_Business_Cards__c WHERE Id = :data.cardId];
           
            if(data.salutation != null) {
                result.Salutation__c = data.salutation;
            }
            if(data.firstName != null) {
                result.First_Name__c = data.firstName;
            }
            if(data.lastName != null) {
                result.Last_Name__c = data.lastName;
            }
            if(data.accountName != null) {
                result.Account_Name__c = data.accountName;
            }
            if(data.title != null) {
                result.Title__c = data.title;
            }
            if(data.phone != null) {
                result.Phone__c = data.phone;
            }
            if(data.mobile != null) {
                result.Mobile__c = data.mobile;
            }
            if(data.fax != null) {
                result.Fax__c = data.fax;
            }
            if(data.email != null) {
                result.Email__c = data.email;
            }
            if(data.website != null) {
                result.Website__c = data.website;
            }
            if(data.street1 != null) {
                result.Street1__c = data.street1;
            }
            if(data.street2 != null) {
                result.Street2__c = data.street2;
            }
            if(data.city != null) {
                result.City__c = data.city;
            }
            if(data.stateCountry != null) {
                result.State_Country__c = data.stateCountry;
            }
            if(data.country != null) {
                result.Country__c = data.country;
            }
            if(data.postcode != null) {
                result.Postcode__c = data.postcode;
            }
            if(data.notes != null) {
                result.Notes__c = data.notes;
            }
            if(data.createdById != null) {
                result.Created_By_Id__c = data.createdById;
            }
            if(data.status != null) {
                result.Status__c = data.status;
            }
            if(data.accountId != null) {
                result.Account__c = data.accountId;
            }
            if(data.contactId != null) {
                result.Contact__c = data.contactId;
            }
                        
        }
        
        else {
                        
            result.Salutation__c = data.salutation;
            result.First_Name__c = data.firstName;
            result.Last_Name__c = data.lastName;
            result.Account_Name__c = data.accountName;
            result.Title__c = data.title;
            result.Phone__c = data.phone;
            result.Mobile__c = data.mobile;
            result.Fax__c = data.fax;
            result.Email__c = data.email;
            result.Website__c = data.website;
            result.Street1__c = data.street1;
            result.Street2__c = data.street2;
            result.City__c = data.city;
            result.State_Country__c = data.stateCountry;
            result.Country__c = data.country;
            result.Postcode__c = data.postcode;
            result.Notes__c = data.notes;
            result.Created_By_Id__c = data.createdById;
            result.Status__c = data.status;
            result.Account__c = data.accountId;
            result.Contact__c = data.contactId;
        }        
        
        try{
            
            upsert result;
                        
            RestContext.response.responseBody = 
                Blob.valueOf(JSON.serialize( 
                    new DTOScannedBusinessCard.Status_CardsIsCreated( '200', result.Id)));
            
            System.debug('170 RestContext.response.responseBody = ' + RestContext.response.responseBody);
            
            
            
        } catch(DMLException e) {
            
            RestContext.response.responseBody 
                = Blob.valueOf(JSON.serialize( new DTOScannedBusinessCard.StatusMessage( 'errorMessage', e.getMessage() ) ));
            
        }
    }
}
ABS(
IF( NOT( ISBLANK( Birthdate ) ) ,
  IF( DATE( 2000 , MONTH( Birthdate ) , DAY( Birthdate ) ) <= 
      DATE( 2000 , MONTH( TODAY() ) , DAY( TODAY() ) ),

      FLOOR(
        (Birthdate - DATEVALUE(Account.CreatedDate)) -
         FLOOR(
         (Birthdate - DATEVALUE(Account.CreatedDate)) / 365.25
              )
      * 365.25
),

      FLOOR(
        (Birthdate - DATEVALUE(Account.CreatedDate)) -
         FLOOR(
         (Birthdate - DATEVALUE(Account.CreatedDate)) / 365.25
              )
      * 365.25
           )
),
  null)
)
Hello,
I tried many times... but receive the same error message : "Challenge Not yet complete... here's what's wrong: 
Formula in custom field 'Account Annual Revenue' is not correct. Check the instructions."
I followed all instructions & get the right results. It's a basic & very simple formula.
Do someone else encounter the same issue ? Any solution ?

Hi,

I have followed several different solutions to this step, but still, I am recieving this error: 

"Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, error: [Name]"

Has anyone got any ideas on how to solve this? 

Please let me know what you need of information from this. I have the following validation rules on opportunity object :
"Approved field validation": 
AND( 
ISCHANGED(Approved__c), 
OR( 
$Profile.Name <> 'System Administrator', 
$Profile.Name <> 'Custom: Sales Profile' 

)

High Value Opportunity Validation:

AND( 
IsClosed = TRUE, 
Amount > 100000, 
Approved__c <> TRUE 
)

Struck on the new trail for the BigObject. Created those Bigobject using workbench. Can see the object on the Org. However, on validating throws up error "Challenge Not yet complete... here's what's wrong: 
Couldn’t find the correct information. Please double check the instructions." bit difficult judge on the problem. I can send the .xml files for verification.
 
In the lesson for "Create Professional Emails in the Feed", I am having an issue with the "Check Challenge" feature:

"Challenge Not yet complete... here's what's wrong:
The Trailhead Service Email Template does not appear to be using the Account Name field."

My email template contains the following fields:

{!Case.Account}

{!Contact.FirstName}

{!Contact.LastName}

It does not seem to recognize the {!Case.Account} for the Account Name requirement.  Am I selecting the wrong merge field?

Hi all, I am so close to finishing this process automation badge but am stuck in one area in Step 7.

I've built out my process builder as follows

User-added image
User-added image
User-added image

And my date formula as follows
 

Case(MOD(Date__c-DATE(1900,1,7),7),0,"Sunday",1,"Monday",2,"Tuesday",3,"Wednesday",4,"Thursday",5, "Friday",6,"Saturday", "")
 



Challenge Not yet complete... here's what's wrong:  The Robot Setup Day of the Week formula does not seem to be working properly. The Day of the Week should not fall on Saturday or Sunday. 

It works nicely but doesn't seem to pass, what could be up.
 

Hi All,
If any one finds difficulties in passing this challenge plz make changes in the VF page:
<apex:outputText value="{!sampleMergeField1}"/> <apex:outputText value="{!HTMLENCODE(sampleMergeField2)}" escape="false"/> <apex:outputText > {!sampleMergeField3} </apex:outputText> <script> document.write('{!JSINHTMLENCODE(sampleMergeField4)}'); </script> {!sampleMergeField5} <script> var x = '{!JSENCODE(sampleMergeField6)}'; </script> <apex:outputLabel value="{!HTMLENCODE(sampleMergeField7)}" escape="false"/>

Thanks,
Ram
  • January 09, 2017
  • Like
  • 2
When checking this challenge, I get an error stating that the quickContact Lightning Component could not be found. Including screenshots of the steps I took thus far. Any advice would be appreciated!

1. The Lightning component must be named quickContact (this comes as part of the package, confirmed in picture below)
User-added image

2. Create a new action with Label Quick Contact and Name Quick_Contact on the Account object that invokes the quickContact component. (confirmed in picture below)
User-added image
3. Add the appropriate interfaces to the quickContact component. (Hint: there are two.) (used the implements force:lightningquickaction AND the force:hasrecordid on line 1, confirmed in picture below)
User-added image

4. Add the action to the Account Layout page layout. (added in picture below)
User-added image
Hello,

I am trying to complete the challenge for the Use Org & Session Cache module on Salesforce Trailhead. Here are the instructions:

In this challenge, you’ll write an Apex class that writes and reads a bus schedule from the org cache. Your method for reading the cache has to handle cache misses.
  • Create a partition called BusSchedule with 0 MB for the size of org cache and session cache. The 0 MB allocation enables you to test cache misses.
  • Create a public Apex class called BusScheduleCache.
  • Add this variable to the class: private Cache.OrgPartition part;
  • In the constructor, create a new instance of Cache.OrgPartition by passing it the partition name (local.BusSchedule). Assign this object to the class variable (part).
  • Add two public methods. a. The first method, putSchedule(), returns void and takes these parameters: String busLine, Time[] schedule. b. The second method, getSchedule(), returns a bus schedule as a time array (Time[]) and takes this parameter: String busLine.
  • Implement the putSchedule() method so that it stores the passed-in values in the org cache by using the partition class variable (part).
  • Implement the getSchedule() method so that it returns the schedule for the specified bus line by using the partition class variable (part).
  • Add logic to the getSchedule() method to handle cache misses. If null is returned for the cached value, getSchedule() should return the following default schedule as a Time array with two Time objects: one Time object value of 8am and another of 5pm. Use the Apex Time.newInstance() method to create the Time objects.
Here is my current code:
 
public class BusScheduleCache {   
    // Get partition
    private Cache.OrgPartition part;
    String partitionName = 'local.BusSchedule';
    
    public BusScheduleCache(String partitionName) {
		Cache.OrgPartition newpart = Cache.Org.getPartition(partitionName);
        part = newpart;
    }
    
    public static void putSchedule(String busLine, Time[] schedule) {
        Cache.Org.put(busline, schedule);
    }
        
    public static Time[] getSchedule(String busLine) {
        Time[] schedule;
        
        // Get a cached value
		Object obj = Cache.Org.get(busLine);
		// Cast return value to a specific data type
		Time t2 = (Time)obj;
        if (t2 != null) {
        	schedule.add(t2);
        }
        else {
            Time t3 = Time.newInstance(8,0,0,0);
            schedule.add(t3);
            Time t4 = Time.newInstance(17,0,0,0);
            schedule.add(t4);
        }        
        return schedule;
    }  
      
}



Here is the error I am receiving:

Challenge Not yet complete... here's what's wrong: 
The Apex Class BusScheduleCache is not properly implemented. Please follow the requirements and ensure everything is setup correctly

Can someone please help?
Hello all,

I'm trying to complete Understand SOQL Injection trailhead and getting right result, but I cannot complete the challenge.

Simulate a SOQL Injection Attack

For this challenge, perform a SOQL injection on the search box to see information that is unintentionally exposed. Navigate to the SOQL Injection Challenge tab within the SOQL Injection application. You will see a search tool for the supply__c object. Use the search box to perform a SOQL injection which returns supplies meant for Nobles only. Hint: If you’ve done this successfully, your query should return one result containing Venison.

I have 4 correct soultions for this:
%' and Nobles_only__c=true and name != '%123
%' and Nobles_only__c=true and name = '%
%' and Nobles_only__c=true and Storage_Location__r.Name != '%
%' and Nobles_only__c=true and Storage_Location__r.Castle__r.Name != '%

All of them are giving only one record containing Venison(what is the requirement). 

Can someone help me? What I'm doing wrong?

Thank you
Getting the following issue while solving the Understand Cross-Site Scripting (XSS) trail under Understand Cross-Site Scripting (XSS) Module.

"There was an unhandled exception. Please reference ID: VNEMXUKK. Error: Faraday::ClientError. Message: INVALID_TYPE: select id from cvcs__c where name = 'xbc1' and ^ ERROR at Row:1:Column:16 sObject type 'cvcs__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names."

The cvcs__c is a custom setting.
 
Hi,
When I am try solving this challenge for Opportunity Checkbox , I get this error.
The validation rule is right no error. I also followed  the answers provided in the solution. Everything seems to be good.Pls lmk 
what debugging can be done.

There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, t2: execution of BeforeInsert caused by: System.NullPointerException: Argument cannot be null. Class.trigger_class.check_opp: line 13, column 1 Trigger.t2: line 2, column 1: []
I am not able to complete the che challenge "Set Up and Manage Shield Platform Encryption". Everytime it shows "The Case Description field does not appear to be encrypted. Make sure you have records with data in this field." Although I encrypted the Case description filed. Anyone have any idea how to get rid of it. Please help me. I am stucked in this step for two days.
The validation rule should be on the Case object.
The validation rule should be named 'Mark_as_Escalated'.
The validation rule should fire if someone tries to set a case as escalated and it is closed, closed when created, or does not have a priority of High.
The validation rule should display the error message 'You can only set a case as escalated if it is high priority and not closed' under the Escalated field when triggered.
Add the 'Escalated' field to the Case page layout.
I am stuck up with this challenge in Visualforce mobile module,Where in i need to use Visualforce page that must display the assistant's phone number using a 'tel:' hyperlink. am getting the above error
Hi All,
If any one finds difficulties in passing this challenge plz make changes in the VF page:
<apex:outputText value="{!sampleMergeField1}"/> <apex:outputText value="{!HTMLENCODE(sampleMergeField2)}" escape="false"/> <apex:outputText > {!sampleMergeField3} </apex:outputText> <script> document.write('{!JSINHTMLENCODE(sampleMergeField4)}'); </script> {!sampleMergeField5} <script> var x = '{!JSENCODE(sampleMergeField6)}'; </script> <apex:outputLabel value="{!HTMLENCODE(sampleMergeField7)}" escape="false"/>

Thanks,
Ram
  • January 09, 2017
  • Like
  • 2
When checking this challenge, I get an error stating that the quickContact Lightning Component could not be found. Including screenshots of the steps I took thus far. Any advice would be appreciated!

1. The Lightning component must be named quickContact (this comes as part of the package, confirmed in picture below)
User-added image

2. Create a new action with Label Quick Contact and Name Quick_Contact on the Account object that invokes the quickContact component. (confirmed in picture below)
User-added image
3. Add the appropriate interfaces to the quickContact component. (Hint: there are two.) (used the implements force:lightningquickaction AND the force:hasrecordid on line 1, confirmed in picture below)
User-added image

4. Add the action to the Account Layout page layout. (added in picture below)
User-added image
Hello All,
I have completed this challenge.

1-For this first you need to create a helper formula field(type-percent) 
Percent Completed :
(DATEVALUE( CreatedDate ) - CloseDate )/100


2- Then you need to create the actual formula field (type- text) by using the helper formula field.
Opportunity Progress :

IF( Percent_Completed__c <=25,"Early", 
IF(Percent_Completed__c <=75,"Middle", 
"Late"))

Thanks,
Nida