+ Start a Discussion
Dhinesh MuralidharanDhinesh Muralidharan 
Hi,
    i am currently doing the above mentioned challenge in the salesforce trailhead. I creatd a permission set and assigned it to the user like it was mentioned and even logged in using the two factor authentication method. but still it is showing challenge not complete. Is there any reason to this. I don't know what i am missing. The following is the error message i received

Challenge Not yet complete... here's what's wrong:
Could not find a user's successful login using two-factor authentication. Make sure you successfully login at least once and that you are prompted for a second factor of authentication

Any help wpuld be appreciated
Best Answer chosen by Dhinesh Muralidharan
Martijn SchwarzerMartijn Schwarzer
Hi Dhinesh,

Just to make sure: Are you logged into the correct developer edition on Trailhead?

Trailhead links to your developer org that you use to login to Trailhead by default. If you've created your solution in another developer org, you will need to disconnect the current developer org from Trailhead and log into your developer org that you've used to create your solution.

You should also check if the user that you used to login actually has an entry with status "Two-factor required" followed by a login attempt with status "Success" like this:

User-added image

Hope this helps!

Best regards,
Martijn Schwärzer
Scott.MScott.M 
Hi,

I don't think this is possible but I might be missing something. What I would like to do is override the New button but only for a specific Record Type.

The normal functionality is that if you have more than one record type, clicking new will take you to a first step where you select the record type and then clicking next takes you to the layout for the record type selected.

I want to keep the first step, and for all but one record type keep the standard creation pages. For the one recordtype I want to display a visualforce page when it's selected in the first step. I'm hoping I don't have to rewrite the first wizard step, any ideas?

Thanks!
Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Sorry for taking so long to come back to this, but there is a (relatively obtuse) way of doing this. What you could do is create an overriding Visualforce or S-Control (soon to be obsolete, right?) page that would determine if the user selected the record type that needs a visualforce page, and if not, then redirect them to the standard page. They'll get the usual "flash" of a blank screen before they get to their destination, but it certainly would work.

 

To get it to work, you need an extension and a page:

 

ApexPage:

 

 

 

<apex:page standardController="Account" extensions="Redirect_extension">

<script>if({!redirect}) window.top.location.href='/001/e?RecordType={!recordtypeid}&nooverride=1'</script>

<!-- Do your custom page here -->

</apex:page>

 


 

 

 

Controller:

 

 

public class Redirect_extension {

private String RecordTypeId, RecordTypeName;

public Redirect_extension(ApexPages.StandardController controller)

{ RecordTypeId = (Case)controller.getRecord().RecordTypeId;

RecordTypeName = '';

for(RecordType rt:[select id,name from recordtype where id = :recordtypeid])

RecordTypeName = rt.name;

}

public boolean getRedirect()

{ if(RecordTypeName=='My Chosen Record Type')

return false;

return true;

}

public string getRecordTypeId()

{ return RecordTypeId;

}

}

 

This is just a rough model, but it looks like it should work. Please feel free to contact me if you need any further help: phyrfoxster at gmail. 

 

Edit: Changed the URL reference from RecordTypeId to RecordType, tried to make the code legible.

Message Edited by sfdcfox on 03-06-2009 09:06 AM
mayur hatkar 7mayur hatkar 7 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: NZCTLCFO
Best Answer chosen by mayur hatkar 7
Akshatha KAkshatha K
Hi Mayur,

I was having the same issue as well. Now it was resolved by adding the label "Recent Items" for the component recent items in the Lightning App Builder.

Reference

Hope this helps!!
ScarScar 

Hi all,

 

I have to change a case owner in a before trigger. The trigger works fine when i use an Administrator profile and the case owner is chnaged to that of a queue, but when i try changing the owner when using a user who's not an admin, i get an error saying that i don't have enough priviledges to perform the action.

 

 

I've put debug logs throughout the code to figure out the error,

The owner id actually is assigned the Queue Id, i think it's during the save operaion that i've missed something or there's an error.

 

can someone please point me in the right direrction and help me figurre out the error?

Best Answer chosen by Admin (Salesforce Developers) 
ScarScar

After lots of time spent searching here and there, i've finally been able to figure the error. 

 

An email is triggered each time a Case or lead owner is changed.  It's because there was en error while firing the email, that i had the insufficient priviledges error and there was not a change in wonership. 

 

To counter the problem , i followed the following  example 

http://help.salesforce.com/apex/HTViewSolution?id=000176854&language=en_US

 

and it worked. :) 

 

Alternately, i could have used WorkFlow rules to change the owner but in my case it would have meant 9 or more  Workflows  depending upon requirements.

 

 

 

EmilienGuichardEmilienGuichard 
Hi all,

I'm stuck in the Apex Integration Services - Apex SOAP Callouts challenge with the following message "The Apex class 'ParkLocator' does not appear to be calling the SOAP endpoint.".

Could you please advise ?
Best Answer chosen by EmilienGuichard
Jeff DouglasJeff Douglas
Try changing line #3 in ParkLocator to: 
ParkService.ParksImplPort park = new ParkService.ParksImplPort();
Sorry... it's case sensitive.  :(

If you had entered ParkService originally it would have generated this code in this manner. Not sure if it didn't overwrite these classes or something.

Jeff Douglas
Trailhead Developer Advocate
BrianHBrianH 

We have an existing class that uses the Test.isRunningTest() method.  Today we tried making changes to that class (completely unrelated to the isRunningTestMethod) and weren't able to save it because of a "method doesn't exist or incorrect signature" error on that method.  Did something change with the Winter 12 release where we can no longer use this in code?  If so, is there something replacing this functionality?  If we should still be able to use it, any thoughts on why we are receiving this error now?


Save error: Method does not exist or incorrect signature: Test.isRunningTest()


Best Answer chosen by Admin (Salesforce Developers) 
spraetzspraetz

Did you add a class to your org named Test?

 

If you add an Apex Class with the same name as a default class in Apex, all calls to that class will look at your class instead of the standard Apex classes.

Felix QuinonesFelix Quinones 

Hello All, 

I'm trying to create a formula field (Yearly Compliance) for a custom object named Compliance. The formula should add the compliance for the quarter (i.e. Q1_c__c), if not left blankand, and divide those by the number of complete fields. I'm trying to calculate the percent of compliance. The problem is that any of those four number fields could be left on black.

I tried the following formulas in where any of the Qs (i.e. Q1_c__c)  could be a number or could be left blank.

IF( 
AND 
   (Q1_c__c =0, 
    Q1_c__c = 0, 
    Q1_c__c = 0, 
   Q1_c__c = 0
    ),
    0, 
(Q1_c__c + Q2_c__c + Q3_c__c + Q4_c__c)/4)

 

IF(

AND(
ISBLANK(Q1_c__c),
ISBLANK(Q2_c__c),
ISBLANK(Q3_c__c),
ISBLANK(Q4_c__c)
),
NULL,(Q1_c__c + Q2_c__c + Q3_c__c + Q4_c__c)/4)

Here is a picture of the pay layout . 

  • If the quarter is left black, means that do not apply.
  • I'm trying to calculate the percent of Yearly Compliance. Here the Yearly Compliance should be 100% divided by 3. This is because the quarter empty (Q1) do not count for this year compliance. Also, the other two quarters are in 0%. 


Example
 

Yearly compliance should be 33.33%
Best Answer chosen by Felix Quinones
Swati PawarSwati Pawar
Hi,

Below mentioned formula might help you.  Make sure to check "Treat blank fields as blanks" option in your formula field.

Formula :
IF(
(Q1__c = 0 ||ISBLANK(Q1__c)) && (Q2__c = 0 || ISBLANK(Q2__c)) && (Q3__c = 0 || ISBLANK(Q3__c)) && (Q4__c = 0 || ISBLANK(Q4__c)) ,
0 ,
((IF(ISBLANK(Q1__c),0,Q1__c) +
IF(ISBLANK(Q2__c),0,Q2__c) +
IF(ISBLANK(Q3__c),0,Q3__c) +
IF(ISBLANK(Q4__c),0,Q4__c) ) )/ 
(IF(ISBLANK(Q1__c),0,1)+ IF(ISBLANK(Q2__c),0,1) +
IF(ISBLANK(Q3__c),0,1) + IF(ISBLANK(Q4__c),0,1))
 
)

User-added image


If it works for you then mark it as a best answer.

Thanks !!
RJ12RJ12 

I'm doing a REST API call to get the global value set and trying to deserialize the JSON result to get the picklist values in a List<String>.

Here is the JSON:

{
  "size": 1,
  "totalSize": 1,
  "done": true,
  "queryLocator": null,
  "entityTypeName": "GlobalValueSet",
  "records": [
    {
      "attributes": {
        "type": "GlobalValueSet",
        "url": "/services/data/v53.0/tooling/sobjects/GlobalValueSet/0Nt59000000AAAAAAA"
      },
      "Metadata": {
        "customValue": [
          {
            "color": null,
            "default": false,
            "description": null,
            "isActive": null,
            "label": "USA",
            "urls": null,
            "valueName": "USA"
          },
          {
            "color": null,
            "default": false,
            "description": null,
            "isActive": null,
            "label": "Canada",
            "urls": null,
            "valueName": "Canada"
          }
        ],
        "description": null,
        "masterLabel": "US States & Territories",
        "sorted": false,
        "urls": null
      },
      "Id": "0Nt59000000AAAAAAA"
    }
  ]
}
I need help in fixing the error and also how to get valueNames in a List<String>

Error: System.JSONException: Malformed JSON: Expected '{' at the beginning of an object.

Here is what I have tried so far:

Wrapper:
    public class GlobalValueSetWrapper{
        Metadata metadata;

    public class Metadata {
        public List<CustomValue> customValue;
    }
    
    public class CustomValue {
        public String label;  
        public String valueName;
    }
    }


Class:
//calling API to get the JSON result
HttpResponse res = GlobalValueSetAPIHandler.getResponse('Countries');
GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) JSON.deserialize(res.getBody(), GlobalValueSetWrapper.class);
Best Answer chosen by RJ12
RJ12RJ12

I'm able to fix it.

public class GlobalValueSetWrapper{
    public List<Records> records;

    public class Records {
        public Metadata metadata;
    }
    
    public class Metadata {
        public List<CustomValue> customValue;
    }

    public class CustomValue {
        public String label;
        public String valueName;    
    }

    public static List<String> getPicklistValues(HttpResponse response){
        List<String> picklistValues = new List<String>();
        
        GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) System.JSON.deserialize(response.getBody(), GlobalValueSetWrapper.class);
        
        for(GlobalValueSetWrapper.customValue value : wrapper.records[0].metadata.customValue){
            picklistValues.add(value.valueName);
        }
        system.debug('Piclist Values: ' + picklistValues);
        
        return picklistValues;
    }
}
merrick devillemerrick deville 
Hello everyone I could use some help on the using future Methods trailhead. Please keep in mind I am not an Apex coder at all but I am trying to learn as much as I can.

Here is the Task

Create an Apex class with a method using the @future annotation that accepts a List of Account IDs and updates a custom field on the Account object with the number of contacts associated to the Account. Write unit tests that achieve 100% code coverage for the class.
Create a field on the Account object called 'Number_of_Contacts__c' of type Number. This field will hold the total number of Contacts for the Account.
Create an Apex class called 'AccountProcessor' that contains a 'countContacts' method that accepts a List of Account IDs. This method must use the @future annotation.
For each Account ID passed to the method, count the number of Contact records associated to it and update the 'Number_of_Contacts__c' field with this value.
Create an Apex test class called 'AccountProcessorTest'.
The unit tests must cover all lines of code included in the AccountProcessor class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

I have written an Apex class and a Test class but I think I am doing them both Wrong: because when I try to check the challenge i Get this error

Challenge Not yet complete... here's what's wrong: 
The 'AccountProcessorTest' test class doesn't appear to be calling the 'AccountProcessor.countContacts' method between Test.startTest() and Test.stopTest().


When I run the Test class I get this error :

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

Here is the CLASS:
 
public class AccountProcessor {
     @future

  public static void someFutureMethod(List<id> scope) {

   Account[] updates = new Account[] {};
        for (AggregateResult ar : [
                select AccountId a, count(Id) c
                from Contact
                where AccountId in :scope
                group by AccountId
                ]) {
            updates.add(new Account(
                    Id = (Id) ar.get('a'),
                    Number_of_Contacts__c = (Decimal) ar.get('c')
                    ));
        }
        update updates;
    }

}

Here is the Test Class:
 
@IsTest
public class AccountProcessorTest {
  public static testmethod void TestAccountProcessorTest() {
 
Test.startTest();
     Account a = new Account();
        a.Name = 'Test Account';
        Insert a;
      
      Contact cont = New Contact();
      
      cont.FirstName ='Bob';
      cont.LastName ='Masters';
      cont.AccountId = a.Id;
      Insert cont;

    Test.stopTest() ;
     Contact ACC = [select AccountId from Contact where id = :a.id LIMIT 1];

 
        System.assert(Cont.AccountId != null);
        System.assertequals(cont.id, ACC.AccountId);

  }}

I have used alot or diffrent google searches to get me this far. But I have not Idea if Im even remotly close to the right answer or not.


 
Best Answer chosen by merrick deville
Amit Chaudhary 8Amit Chaudhary 8
As per task you method should be "countContacts"

Please update your Apex class like below :-
public class AccountProcessor 
{
  @future
  public static void countContacts(Set<id> setId) 
  {
      List<Account> lstAccount = [select id,Number_of_Contacts__c , (select id from contacts ) from account where id in :setId ];
      for( Account acc : lstAccount )
      {
          List<Contact> lstCont = acc.contacts ;
          
          acc.Number_of_Contacts__c = lstCont.size();
      }
      update lstAccount;
  }
}

Test class:-
@IsTest
public class AccountProcessorTest {
    public static testmethod void TestAccountProcessorTest() 
    {
        Account a = new Account();
        a.Name = 'Test Account';
        Insert a;

        Contact cont = New Contact();
        cont.FirstName ='Bob';
        cont.LastName ='Masters';
        cont.AccountId = a.Id;
        Insert cont;
        
        set<Id> setAccId = new Set<ID>();
        setAccId.add(a.id);
 
        Test.startTest();
            AccountProcessor.countContacts(setAccId);
        Test.stopTest();
        
        Account ACC = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];
        System.assertEquals ( Integer.valueOf(ACC.Number_of_Contacts__c) ,1);
  }
  
}

Please let us know if this will help you

Thanks
Amit Chaudhary
 
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12 
I want to use Apex code and visualforce page to create a new lead.

In web, I need to choose a record type before I create a new lead. And there are three types of leads.
In visualforce page, I want to create a new lead with assigned record type using code.

The confusion for me is that the recordType is related list for the lead. I could extract a list of record type by the following.

for (list<RecordType> rts : [SELECT ID, name FROM RecordType WHERE SObjectType = 'Lead' Order by name])

However, I could not pull out the recordType for a lead by the following, since the recordType is related list.

Lead l = [SELECT RecordType FROM LEAD].

Besides, what I want is create a new lead like below.
Lead l = new Lead(firstname='testInsertLead2', lastname='test',company='Temp Company', RecordType = 'registration type lead');

Could anyone help me with this to access the related list using apex code or visualforce page?

Thanks a lot.


Best Answer chosen by msb-appsupport1.3905906418879758E12
Chidambar ReddyChidambar Reddy
Hi

Try the following it will be user friendly



Map<String,Id> recordtypeMap  = new Map<String,Id>();

for(Record Type leadRT :  [select id, Name from RecordType where SObjectType = 'Lead' ]){

recordtypeMap.put(leadRT.Name,leadRT.Id);
 }

//you can create lead by following 

Lead l = new Lead(firstname='testInsertLead2', lastname='test',company='Temp Company', RecordTypeId = recordtypeMap.get('registration type lead'));

// be sure to enter record type name correctly other wise it would give an error.



Thank you,
Choose it as Best Answer if it resolved your issue.