+ Start a Discussion
__ 

I have a date time string from external system that is represented as 10/13/2011 10:36:07 AM

Need to put it in datetime field on sf object. when try to do datetime.parse ('10/13/2011 10:36:07 AM'); it gives me type exception, invalid date time... any workarounds?

Best Answer chosen by Admin (Salesforce Developers) 
spraetzspraetz

If you remove the seconds from the time and use

 

datetime.parse ('10/13/2011 10:36 AM');

 

instead, it works. 

 

I also noticed that our documentation for datetime.parse is pretty lacking.  That will be corrected soon.

 

Thanks for pointing this out.

 

 

Lucas NogueiraLucas Nogueira 
Hello, I am encountering the following message Challenge Not yet complete... here's what's wrong:
The 'My Shifts Pending Approval' report does not have the correct columns. Of the two 'Volunteer Shift Worker ID' fields, include the one with the format Shift-#### so users can click through to the volunteer record.


Can anyone help me with this?

User-added image
User-added image
Best Answer chosen by Lucas Nogueira
Lucas NogueiraLucas Nogueira
Hi!

I solve the problem, yay! I need adding the field Volunteer Job in the record type, for some reason this field notting adding automatically.

Thanks a lot for all!!!
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 

 
HAZLITT VASUDEVANHAZLITT VASUDEVAN 
String a = 'Hello. \n Welcome to salesforce, \n Name \n Asian Paints \n WO Number \n 12345678 \n Account Id \n 1547586597';
        List<String> lst = new List<String>();
        lst=a.split('\n');
        System.debug(lst);

output I got in a same line with a comma.
Best Answer chosen by HAZLITT VASUDEVAN
Maharajan CMaharajan C
Hi Hazlitt, 

Instead of  \n you can directly use the  \r\n  in String.
String a = 'Hello. \r\n Welcome to salesforce, \r\n Name \r\n Asian Paints \r\n WO Number \r\n 12345678 \r\n Account Id \r\n 1547586597';

system.debug(' a ==> ' + a);

( OR  you can use the below code )
 
String a = 'Hello. \n Welcome to salesforce, \n Name \n Asian Paints \n WO Number \n 12345678 \n Account Id \n 1547586597';
List<String> lst = new List<String>();
lst=a.split('\r\n');
System.debug(lst);

Thanks,
Maharajan.C

 
KMK91KMK91 
Hi All
Did any one have any idea how to display Questions under that radio buttons(Using LWC) and help text?

Thanks
KMK
Best Answer chosen by KMK91
ShivankurShivankur (Salesforce Developers) 
Hi,

Please check out the implementation provided over the below link, if it helps you implement similar as per your business requirement:
https://salesforce.stackexchange.com/a/313367/96007

Hope above information helps. Please mark as Best Answer so that it can help others in future.

​​​​​​​Thanks.
TUSHAR MATHUR 35TUSHAR MATHUR 35 
Hi all, I just seen that lightning:fileupload won't work on lightning out or standalone apps. i have seen a code for custom file upload using apex .
but i can't see the files where those files has been uploaded here is the link from where i get it to learn. please help me .
Thanks
Custom File Uploader (https://sfdcmonkey.com/2017/09/25/file-upload-lightning-component/)
Best Answer chosen by TUSHAR MATHUR 35
TUSHAR MATHUR 35TUSHAR MATHUR 35
Hi Abhinav thanks for response,
yes you are absolutely right .i already included that parent id as my custom objects record id. yes in account it will work,  but not for other objects .
Work around to this is just goto your custom object and then just edits its page layout and then in related list just add notes and attachments and its done. Now you will see it in  that record which is from custom object. 
Michael MMichael M 
Hello, we want to create a connected app to allow api access to our Salesforce org. However we only want to be able to give the connected app access to very specific records (e.g. where the accountid = a specific account id). Is that possible?
Best Answer chosen by Michael M
VinayVinay (Salesforce Developers) 
Hi Michael,

As per my understanding,  We cannot restrict access to certain records using connected app.  However you can restrict cccess to APIs check below reference.

https://help.salesforce.com/articleView?id=sf.security_api_access_control_all_users.htm&type=5

Hope above information was helpful.

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

Thanks,
nagasnagas 

hi I have a ApexScheduler Class which need to be test inorder to
deploy can anybody suggest me the way to achieve it to get the
coverage. I am posting the code below

 

global class ScheduleTerritoryInactiveMemberCheck implements 
Schedulable { 
    global void execute(SchedulableContext SC) { 
        TerritoryInactiveMemberCheck bcc = new 
TerritoryInactiveMemberCheck(); 
          bcc.query = 'select id,name from territory'; 
             Database.executeBatch(bcc,200); 
  }
 
} 

 cheers,

naga

 

Best Answer chosen by Admin (Salesforce Developers) 
BritishBoyinDCBritishBoyinDC

 

public static testMethod void testschedule() {

Test.StartTest();

ScheduleTerritoryInactiveMemberCheck sh1 = new ScheduleTerritoryInactiveMemberCheck();

String sch = '0 0 23 * * ?'; system.schedule('Test Territory Check', sch, sh1); Test.stopTest(); }

 

 

 

How to convert S-Control to VFHow to convert S-Control to VF 

Hi,

 

How to deploy data and meta data from Developer Edition to Sandbox.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

There are multiple ways to do this :

 

1) Deploy using Eclipse

2) Create a package and deploy it to sandbox

 

Now if you want to deploy the data then :

 

1) You can do this using Data loader

2) You can use import wizard

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Hitesh KhannaHitesh Khanna 
trigger contactTrigger on Contact (before insert,after insert,before update,after update,after undelete,after delete)
{
    if(trigger.isAfter){
        List<Contact> contactList = new List<Contact>();
        Set<Id> accountIdSet= new Set<Id>();
        if(trigger.isDelete){
            contactList=Trigger.old;
        }else{
            contactList=Trigger.new;
        }
        
        for(Contact con :contactList){
            if(con.AccountId!=null){
                accountIdSet.add(Con.AccountId);
            }
            if(Trigger.isUpdate){
                 Contact oldContact  = (Contact)Trigger.oldMap.get(con.Id);
            if(oldContact.AccountId != con.AccountId){
                accountIdSet.add(oldContact.AccountId);
            }
            }
           
        }
      List<Account> accountList = [SELECT Id,Name,Number_Of_Contacts__c,(select Id,Name From Contacts)
                                   FROM Account 
                                  WHERE Id IN:accountIdSet];
        for(Account acc: accountList){
            List<Contact> relatedContacts = acc.Contacts;
            if(relatedContacts !=null){
                acc.Number_Of_Contacts__c = relatedContacts.size();
                
            }else{
                acc.Number_Of_Contacts__c=0;
            }
        }
        update accountList; 
     
    }
    
}
Best Answer chosen by Hitesh Khanna
CharuDuttCharuDutt
Hii Hitesh
Try Below Code
public class relatedContact {
    
     public static void insertRecord( list<Contact> lstCon){
         List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
   
        for(Contact con : lstCon){
            if(con.AccountId != null){
            setAccIds.add(con.AccountId);
                }
            }
         for(Account acc :[Select id,Total_Contacts__c ,Description ,(Select id,name,Salary__c from contacts) from Account where Id in : setAccIds]){
      acc.Total_Contacts__c = acc.contacts.size();
        acclist.add(acc);
    }
    if(acclist.size()>0){
        update accList;     
    }
     }
    public static void updateRecord( list<Contact> lstCon,Map<Id, Contact> oldLeads){
         List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
   
        for(Contact con : lstCon){ 
            if(con.AccountId!=oldLeads.get(con.Id).AccountId){
                   setAccIds.add(con.AccountId);
                setAccIds.add(oldLeads.get(con.Id).AccountId);
                }
            }
        
         for(Account acc :[Select id,Total_Contacts__c ,Description ,(Select id,name,Salary__c from contacts) from Account where Id in : setAccIds]){
      acc.Total_Contacts__c = acc.contacts.size();
        acclist.add(acc);
    }
    if(acclist.size()>0){
        update accList;     
    }
     }
        public static void DeleteRecord( list<Contact> oldLeads){
         List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
   
        for(Contact con : oldLeads){ 
            
                   setAccIds.add(con.AccountId);
                
            }
        
         for(Account acc :[Select id,Total_Contacts__c ,Description ,(Select id,name,Salary__c from contacts) from Account where Id in : setAccIds]){
      acc.Total_Contacts__c = acc.contacts.size();
        acclist.add(acc);
    }
    if(acclist.size()>0){
        update accList;     
    }
     }
   
}


Trigger

trigger NumberOfChild on Contact (After Insert,After Update,After Delete) {
 if(Trigger.isInsert){
         if(trigger.isAfter){
      relatedContact.insertRecord(trigger.new);
        }
    } 
   
    if(Trigger.isUpdate){
         if(trigger.isAfter){
              relatedContact.updateRecord(trigger.new,trigger.oldMap);
        }
    }
    if(Trigger.isDelete){
        if(trigger.isAfter){
      relatedContact.DeleteRecord(trigger.old);
        }
    }    
}
Test Class
@isTest
public class NumberOfChildTest {
@isTest
    public Static Void UnitTest(){
        Account Acc = new account();
        Acc.name ='test';
        insert Acc;
        
        Account Acc2 = new account();
        Acc2.name ='test2';
        insert Acc2;
        
        Contact Con = new Contact();
        Con.LastName = 'TestCon';
        Con.AccountId = Acc.Id;
        Insert Con;
        Con.AccountId = Acc2.Id;
        Update Con;
        Delete Con;
    }
}

Please Mark It As Best Answer If it Helps Thank You!