You need to sign in to do that
Don't have an account?

What is the maximum number of Lookup realtionships on a Standard Object
Hi
Please answer the fourth question here:
Maximum number of Master-Detail realtionships on a Custom Object is : 2
- Maximum number of Master-Detail realtionships on a Standard Object is : 0
- Maximum number of Lookup realtionships on a Custom Object is : 25
- Maximum number of Lookup realtionships on a Standard Object is :
Thanks,
Priya.

Not able to get one (battery) of the JSON string value, getting other values but not battery. please help me.
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);
}
}


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.

control acces to fields profile does not have the appropriate field-level security for the account Rating field.

Please once again confirm these steps, because i was able to pass doing this, also make sure you have selected right trailhead org.
if you still face problem let me know.
Thanks
Saurabh

Using API's without authentication
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

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
How would you update permissions so that an Account Owner can change all related Contact Owners?
How would you update permissions so that an Account Owner can change all related Contact Owners?
Thanks for any help!

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

Master Detail Relationship Deployment is Failing
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?




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,

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?




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

Batch Apex to Delete Duplicate records with same Email id
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){ } }

global class removeDuplicateRecords implements Database.Batchable<SObject> , Database.Stateful {
-Thanks,
TK

Create an Apex class that uses the @future annotation to update Account records.
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);
}
}

Unexpected INVALID_FIELD_FOR_INSERT_UPDATE when merging 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.

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