+ Start a Discussion
PRIYAPRIYAPRIYAPRIYA 

Hi

 

Please answer the fourth question here:

 

  1. Maximum number of Master-Detail realtionships on a Custom Object is : 2

  2. Maximum number of Master-Detail realtionships on a Standard Object is : 0
  3. Maximum number of Lookup realtionships on a Custom Object is : 25
  4. Maximum number of Lookup realtionships on a Standard Object is :

Thanks,

Priya.

Best Answer chosen by Admin (Salesforce Developers) 
@anilbathula@@anilbathula@

Hi,

 

Yes the custom lookup fields on  both the objects are 25 only.

But there is an advantage in the standard object where u can get some more lookup fields by standard functionality .

Apart  from that u can have 25 custom lookup fields in standard object and custom object.

 

Thanks

Anil.B

 

Prashanth Kumar Singh Poorna SinghPrashanth Kumar Singh Poorna Singh 
Public Class JSONParseDisplay{


Public Static void ParseJSON() {

  
  String Jsonstrn = '{"userDevices":[{"asserts":[" 2015-8-06 22:48:00"," 2015-8-06 22:48:00"],"battery":{"percentage":20,"voltage":3745},"deviceId":29308103,"deviceSerialNumber":"12EB5676534B","deviceType":"Charge HR","deviceWireId":"eb5672212b12","fwVersionRaw":"APP18.84 BSL18.84","hardwareVersion":"9","lastSyncClient":"api/sync-CLIENT-VISIBLE/mobile-ios/401","lastSyncedAt":"2015-08-10T13:27:56.000Z","pairedAt":"2015-04-10T19:51:15.000Z","pairedToEmail":"afit@somewhere.com"}]}';

//String Jsonstrn = '{"userDevices":[' +'{"asserts":[" 2015-8-06 22:48:00"," 2015-8-06 22:48:00"],"battery":[' +'{"percentage":20,"voltage":3745}],"deviceId":29308103,"deviceSerialNumber":"12EB5676534B","deviceType":"Charge HR","deviceWireId":"eb5672212b12","fwVersionRaw":"APP18.84 BSL18.84","hardwareVersion":"9","lastSyncClient":"api/sync-CLIENT-VISIBLE/mobile-ios/401","lastSyncedAt":"2015-08-10T13:27:56.000Z","pairedAt":"2015-04-10T19:51:15.000Z","pairedToEmail":"afitbitter@somewhere.com"}' +']}';

   JSONParser parser = JSON.createParser(Jsonstrn);
   System.debug('parser' +parser);
   while (parser.nextToken() != null) {
   
     if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
     
         while (parser.nextToken() != null) {
         
          if (parser.getCurrentToken() == JSONToken.START_OBJECT) {
          
          
          UserDevice usd = (UserDevice)parser.readValueAs(UserDevice.class);
          System.debug('usd++ : ' +usd);
          System.debug('pairedAt: ' +usd.pairedAt);
          
         // System.debug('Size of batteries: ' +usd.batteries.size());
          System.debug('batteries: ' +usd.batteries);
          
          String s = JSON.serialize(usd);
          System.debug('Serialized invoice: ' + s);
          
          parser.skipChildren();
              
           }
              
        }

     } 
    
   }

 }
 
 public class UserDevice {
        
        List<string> asserts;
       List<battery> batteries;
      // List<string> batteries;
        public Double deviceId;
        public string deviceSerialNumber;
        public string deviceType;
        public string deviceWireId;
        public string fwVersionRaw;
        public Double hardwareVersion;
        public string lastSyncClient;
        public string lastSyncedAt;
        public string pairedAt;
        public string pairedToEmail;
        
        public UserDevice(List<string> asser,List<battery> batt,Double devId,string deviceSerNumber,string devType,string devWireId,string fwVersRaw,Double hardVersion,string lastSyClient,string lastSyedAt,string paredAt,string paredToEmail){
        
        asserts = asser;
       batteries = batt.clone();
       // batteries = Double.parseDouble(batt);
      // batteries = batt;
      //  System.debug('batt.clone(): ' +batt.clone());
        deviceId = devId;
        deviceSerialNumber = deviceSerNumber;
        deviceType = devType;
        deviceWireId = devWireId;
        fwVersionRaw = fwVersRaw;
        hardwareVersion = hardVersion;
        lastSyncClient = lastSyClient;
        lastSyncedAt = lastSyedAt;
        pairedAt = paredAt;
        pairedToEmail = paredToEmail;
        
        System.debug('pairedToEmail: ' +pairedToEmail);
   }     
 
 }
 
 public class battery {
        public Double percentage;
        public Double voltage;
        //System.debug('voltage::' +voltage);     
 
 
 } 


}
Best Answer chosen by Prashanth Kumar Singh Poorna Singh
Muthuraj TMuthuraj T
public class UserDevice{
    List<UserDevices> userDevices;
} 
public class UserDevices {
        
        List<string> asserts;
        public battery battery;
        public Double deviceId;
        public string deviceSerialNumber;
        public string deviceType;
        public string deviceWireId;
        public string fwVersionRaw;
        public Double hardwareVersion;
        public string lastSyncClient;
        public string lastSyncedAt;
        public string pairedAt;
        public string pairedToEmail;
 }
 
 public class battery {
        public Double percentage;
        public Double voltage;
 } 

String Jsonstrn = '{"userDevices":[{"asserts":[" 2015-8-06 22:48:00"," 2015-8-06 22:48:00"],"battery":{"percentage":20,"voltage":3745},"deviceId":29308103,"deviceSerialNumber":"12EB5676534B","deviceType":"Charge HR","deviceWireId":"eb5672212b12","fwVersionRaw":"APP18.84 BSL18.84","hardwareVersion":"9","lastSyncClient":"api/sync-CLIENT-VISIBLE/mobile-ios/401","lastSyncedAt":"2015-08-10T13:27:56.000Z","pairedAt":"2015-04-10T19:51:15.000Z","pairedToEmail":"afit@somewhere.com"}]}';

UserDevice ud = (UserDevice)JSON.deserialize(Jsonstrn,UserDevice.class);
system.debug(':::'+ud);
system.debug('Battery::'+ud.UserDevices[0].battery);



Output:

|DEBUG|:::UserDevice:[userDevices=(UserDevices:[asserts=( 2015-8-06 22:48:00,  2015-8-06 22:48:00), battery=battery:[percentage=20.0, voltage=3745.0], deviceId=2.9308103E7, deviceSerialNumber=12EB5676534B, deviceType=Charge HR, deviceWireId=eb5672212b12, fwVersionRaw=APP18.84 BSL18.84, hardwareVersion=9.0, lastSyncClient=api/sync-CLIENT-VISIBLE/mobile-ios/401, lastSyncedAt=2015-08-10T13:27:56.000Z, pairedAt=2015-04-10T19:51:15.000Z, pairedToEmail=afit@somewhere.com])]

|DEBUG|Battery::battery:[percentage=20.0, voltage=3745.0]

Please try with the above code. I hope this helps you.
Satria Akbar NugrohoSatria Akbar Nugroho 
Hi, i'm trying to finish the challenge i already follow the steps but i got an error sales profile does not have the appropriate field-level security for the account Rating field. do you know how can i fix this ?
User-added image
User-added image
Best Answer chosen by Satria Akbar Nugroho
Saurabh TyagiSaurabh Tyagi
Hi Satria,

Please once again confirm these steps, because i was able to pass doing this, also make sure you have selected right trailhead org.

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


if you still face problem let me know.

Thanks 
Saurabh
 
Roman RauerRoman Rauer 
Hi there :)

i'm currently working on an native Android app for my company and ran into some problems with Salesforce lately.

I hope i can find some help here.

What i want to achieve:
The company has a lot of Accounts in Salesforce with 3 important fields for the app: Name, Business (Workshop or Parts Dealer) and location(latitude, longitude)
I would like to show those Accounts(Workshops/Parts Dealers) as markers on a google map in my Android app based on a radius around the user's current location. So it would be more than sufficient to get the data as JSON or XML(i read about sObjects, which would be nice too)

The app will be freely available on Google Play Store and every user should be able to see all the Workshops/Parts dealers around the world.

The problem i'm facing is that i can't find a way to fetch the data inside my app without authenticating every user with a Salesforce-Login. 
Which API is the best to use in this case?

It would be so awsome if anybody could help me with this problem.

What i tried so far: 
- SalesforceMobileSDK: If i extend SalesForceApplication i always end up with the Salesforce-Login Screen.
It seems that every client has to be authenticated for API-calls to work. I tried using the method "peekUnauthenticatedRestClient", but this method only works on full path URL's(e.g. "https://api.spotify.com/v1/search?q=James%20Brown&type=artist"), which isn't really practically for my Use-case.

- I feel like i read nearly all docs about salesforce api, but can't quite get my head around how to solve this problem, although it seems like to be a pretty common use-case.  

- would a salesforce-apex method which would select all records inside a set radius around the user's location be accessable without authentication?

Thanks for your help in advance!

Roman
Best Answer chosen by Roman Rauer
Santosh Bompally 8Santosh Bompally 8
Follow this -> 
1) Write a Restservice to expose your data. 
@RestResource(urlMapping='/Account')
global with sharing class MyRestResource {

 
    @HttpGet
    global static List<Account> doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
       List< Account>  result = [SELECT Id, Name, Business,Location FROM Account ];
        return result;
    }
  
}

2)  Create a Community and provide access to apex class and account object to the Guest user profile. 
    Samplecommunity url -> https://somedomain.cs16.force.com/communityname

3) Go to workbench and test your API using rest explorer 
    relative url ->  /services/apexrest/Account
4) Your public url will now be   https://somedomain.cs16.force.com/communityname/services/apexrest/Account 

Mark as Best Answer if it helps. 

Thanks, 
Santosh 

 
Riley BroachRiley Broach 

How would you update permissions so that an Account Owner can change all related Contact Owners? 

Thanks for any help!

Best Answer chosen by Riley Broach
Suraj Tripathi 47Suraj Tripathi 47

Hi, Riley

You can take references from these steps.

 

Give users permission to change Account ownership
 DescriptionUsers can have the ability to transfer records to which they have edit access, including changing Account ownership.
 
ResolutionTo accomplish this the "Transfer Records" permission must be added to the users' Profile, or a Permission Set with the permission assigned to them.
Give permission to Transfer Records
Salesforce Classic


To set the permissions on a Profile:
Navigate to Setup | Administration Setup | Manage Users | Profiles
Click on Edit next to the new custom Profile you created
Check the box next to 'Transfer Records'
Click Save


To set the permissions for a Profile using the Enhanced Profile editor: 
Navigate to Setup | Administration Setup | Manage Users | Profiles
Click on the name of the new custom Profile you created
Click on System Permissions
Check the box next to 'Transfer Records'
Click Save


To create a Permission Set:
Navigate to Setup | Permission set
Click the New button, enter Label and API Name, then click next
Click on System Permissions
Click on Edit
Check the box next to 'Transfer Records' then click Save
Click "Manage Assignments"
Click "Add Assignments"
Put a check next to the users who need this permission, then click Assign
Lightning Experience:

To set the permissions for a Profile:

1. Click on the Gear Icon | Select Setup | Type in "Profiles" on the Quick Find box
2. Click on Edit next to the new custom Profile you created
3. Check the box next to 'Transfer Record'
4. Click Save  

To set the permissions for a Profile using the Enhanced Profile editor: 

1.Click on the Gear Icon | Select Setup | Type in "Profiles" on the Quick Find box
2. Click on the name of the new custom Profile you created
3. Click on System Permissions
4. Check the box next to 'Transfer Record'
5. Click Save

To create a Permission Set
Navigate to Setup | Permission set
Click the New button, enter Label and API Name, then click next
Click on System Permissions
Click on Edit
Check the box next to 'Transfer Records' then click Save
Click "Manage Assignments"
Click "Add Assignments"
Put a check next to the users who need this permission, then click Assign

 

I hope it will help you. 

Thank You

Surya KusampudiSurya Kusampudi 

Here is the scenario,

> Create 2 Master Detail relationship fields and 2 Lookup fields on any Custom Object
> Deploy these changes to target Org
> Now convert 1 master-detail relationship to lookup field and 1 lookup field to master-detail relationship field

> Now again deploy this change to the target org and it fails with the below error message.

 

Error: You cannot create this type of field because this object already has two master-detail relationships.
 

Technically, master-detail already converted to look-up relationship so it should just update the field on the target org. But it is not happening?

Any explanation would be helpful?

Best Answer chosen by Surya Kusampudi
VinayVinay (Salesforce Developers) 
Hi Surya,

Salesforce will not accommodate a master-detail relationship or lookup relationship to a object that already contains data.

You would need to add this as post-migration step and convert manually.  Check below reference for more details.

https://help.salesforce.com/articleView?id=000325374&type=1&mode=1

Thanks,
Muhammad Saffi UllahMuhammad Saffi Ullah 
Hi I am geeting "Error: ConvertLead failed. First exception on row 0; first error: UNAVAILABLE_RECORDTYPE_EXCEPTION, Unable to find default record type: []"
When converting lead? Is there anything I am missing?
Best Answer chosen by Muhammad Saffi Ullah
PriyaPriya (Salesforce Developers) 

Hi Muhammad,

Causes of the 'Record type unavailable' error when converting a Lead
1. The Organization has Person Accounts enabled and the affected User's profile does not have access to the Person Account and/or Business Account record types.

Salesforce Classic
Click Setup.
Under Manage User, click on Profiles.
Select the Profile of the affected user.
Under Record Type Settings Section, click on Edit.
Add the Person Account Record Type.
Click Save.
Lightning Experience
Click the gear icon.
Click Setup.
Under Users, click on Profiles.
Select the Profile of the affected user.
Under Record Type Settings Section, click on Edit.
Add the Person Account Record Type.
Click Save.
**Steps for Orgs that have Enhanced Profile User Interface is enabled in Lightning Experience

Click the gear icon.
Click Setup.
Under Users, click on Profiles.
Select the Profile of the affected user.
Select Object Settings
Select the Object
Click Edit
Ensure that that the box in the person accounts row is checked under assigned record type
Also ensure that it was a default record type.
Click Save.
2. Either the record owner or the User converting the record lack access to the appropriate record type.
3. The affected User's profile has the default record type set to '-Master-' for the Account, Contact, Opportunity and/or Task objects.
To resolve this error, check the points above.  Make sure that the record types are made available for the profile, and that the default record type is set appropriately for the objects listed above.

Please mark as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan

Sandhya K 10Sandhya K 10 
I have a custom Object Book3__c , In which I have the records as Below.

Name          Email__c
Book1    hh@gmail.com
Book2    hh@gmail.com

Book3    gg@gmail.com
Book4    gg@gmail.com

Book5    kk@gmail.com
Book6    kk@gmail.com
Book7    kk@gmail.com

The problem with the below code is, It deletes all the records . But I need to Keep one and delete the remaining. What Am I missing here.?
 
Global class removeDuplicateRecords implements Database.Batchable<SObject> , Database.Stateful {
    
    global Set<String> emailstring;
    
    global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator([Select Email__c from Book3__c where Email__c != null]);
      }
    
    global void execute(Database.BatchableContext BC , List<Book3__c> scope){
        
        Set<String> emailstring = new Set<String>();
        
      //  Map<String , Book3__c> EmailBookmap = new Map<String , Book3__c>();
        for(Book3__c s : scope){
        // EmailBookmap.put(s.Email__c , s);
            emailstring.add(s.Email__c);
            
        }  
       // system.debug(EmailBookmap);
        system.debug(emailstring);
        
        List<Book3__c> bklst = [select Email__c from Book3__c where Email__c In :emailstring ];
        
        List<Book3__c> duplicatelist = new List<Book3__c>();
        
        for(Book3__c bk : Scope){
        for(Book3__c b :bklst){
           // if(emailstring.contains(b.Email__c)){
            if(bk.email__c == b.email__c){
              duplicatelist.add(b);  
            }
            else{
             emailstring.add(bk.Email__c);   
            }
        }
        }
        
       // system.debug(EmailBookmap);
        system.debug(duplicatelist);
      delete duplicatelist;
    }
    
    global void finish(Database.BatchableContext BC){
        
    }
        

}

 
Best Answer chosen by Sandhya K 10
Tarun J.Tarun J.
Update first line as below:
 
global class removeDuplicateRecords implements Database.Batchable<SObject> , Database.Stateful {

-Thanks,
TK
Glenn Dailey 1Glenn Dailey 1 
The 'AccountProcessor' class did not achieve 100% code coverage via your test methods. Make sure that you chose 'Run All' tests in the Developer Console at least once before attempting to verify this challenge. I did the run all with no luck. I did notice that this is the new section that was just added and I ran into issues in the first unit too.

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.

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;
  }
}

and
@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);
  }
 
}
Best Answer chosen by Glenn Dailey 1
Amit Chaudhary 8Amit Chaudhary 8
I am glad that works. PLease mark best answer and close this thread so that if some one has same issue that post can help other
Daan LuttikDaan Luttik 
Our goal is to merge Contacts (and later Accounts) in Salesforce CRM. Our data is already polluted therefore we can't rely on merge rules that are triggered only for new/changed contacts.

Therefore we think that we need to utilize Apex code however we are running into some issues that seem to have to do not with the code but with the permissions:
(Important to note about the code below, the emails in the contacts are fake and can therefore be ignored completely when merging).
public class MergeRule {
    public static void applyMergeRule() {
        AggregateResult[] contacts = [
            SELECT Name, BirthDate, COUNT(Email) nr
            FROM Contact GROUP BY Name, BirthDate
            HAVING COUNT(Email)>1
        ];
        for (AggregateResult contact_group: contacts) {
            String name = (String)contact_group.get('Name');
            Date birth_date = (Date)contact_group.get('BirthDate');
            Contact[] contact_subgroup = [
                SELECT Id, Name, BirthDate
                FROM Contact
                   WHERE Contact.Name = :name
                   AND Contact.BirthDate = :birth_date
						];
            for (Integer i=1; i<contact_subgroup.size(); i++){
								// This line produces the error 👇 🔔
                merge contact_subgroup[0] contact_subgroup[i];
            }
        }
    }
}

We receive the following error:
14:07:03:138 FATAL_ERROR System.DmlException: Merge failed. First exception on row 0 with id 0035r000002VYMoAAO; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
We have tried to change the field level security for the profile System Admin on the field Name for the Contacts object, however, we found that there is no way to change this field. We tried this due to the suggestions in this thread on the salesforce development forum (https://developer.salesforce.com/forums/?id=9060G0000005PvhQAE) and this thread on the salesforce stackexchange (https://salesforce.stackexchange.com/questions/69857/how-to-check-whether-a-user-has-write-access-to-a-field), however, we are not completely sure that we interpreted these threads correctly (maybe we need to change the permissions for other profiles, objects or fields instead of the ones above?)

I hope that you can help us with this issue.
Best Answer chosen by Daan Luttik
Daan LuttikDaan Luttik
For us, the issue, in the end, was that we retreived the contact not only with the Id but also with the Name and BirthDate.
When we changed the contact_subgroup query to the following it all worked:
Contact[] contact_subgroup = [
SELECT Id,
FROM Contact
WHERE Contact.Name = :name
   AND Contact.BirthDate = :birth_date
];