• Pranav Chitrans
  • NEWBIE
  • 174 Points
  • Member since 2015


  • Chatter
    Feed
  • 3
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 61
    Replies
Hi,

I need one help for Cron Expression for sechduling my batch at certain interlval which would be a lighitning web component, and whatever period sleected in the drop down i will take that sync period as my parameter to calculate cron expression. My interval could be every 30 minute, hourly, daily. And the moment user click on custom sechdule button from LWC page from that time the calculation should start, not from the near by hours. For example user click on button at 18th July 2019 10:34 A.M and he seleted the interval from drop down as '30 Minutes' then the next sechdueld run should be 18th July 2019 11:04 A.M, not the 10:30 A.M because salesforce takes the near by hours by default which i did not wanted in my solution.

I have written the logic for hourly and daily which seems workin fine but i am ot sure too for that as well.
if(syncPeriod == 'Every 30 Minutes') {
	cronExpressionfromUI = '0 '+system.now().addMinutes(30).minute()+' * * * ?';
	
	cronExpressionfromUI = '0 10'+' *'+' *'+' *'+' ?';
	}
	else if(syncPeriod == 'Hourly') {
		cronExpressionfromUI = '0 '+system.now().minute()+' * * * ?';
	}
	else if(syncPeriod == 'Daily') {
		cronExpressionfromUI = '0 0 '+system.now().addHours(1).hour()+' *'+' *'+' ?';
	}
}
For the first condition( every 30 minute) i am facing an issue which are listed below :
  • If i use expression('0 '+system.now().addMinutes(30).minute()+' * * * ?') the it runs for the 1 st time but for the next run after completion of one it gets sechduled for 1 hour automatically.
  • If i use expression for 10 minute(for testing purpose) something like(cronExpressionfromUI = '0 10'+' *'+' *'+' *'+' ?';) then it always calculate from the near by hours not the moment from when button was clicked.
  • I do not want to run the system.sechdule multiple time as per my sync interval timing because that might hit governer limit.
I tried few other expression as well, but i wont help.
Please assist at earliest.

Thanks
Pranav
 
I don't have previous experience with Apex Code. I created an apex class that converts the Lead to Account and I write a simple test. With the current status my code coverage is 44% and I need at least 75% in order to deploy it in production. Can someone help me write that ?


Apex Class
Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus('Qualified');
                MassLeadconvert.add(Leadconvert);
        }
        
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}
Test Class
@isTest
private class AutoConvertLeads_Test{
  static testMethod void test_LeadAssign_UseCase1(){
    AutoConvertLeads obj01 = new AutoConvertLeads();
    AutoConvertLeads.LeadAssign(new List<Id>());
  }

}


 
I have two related custom objects. I'll name them:
"Custom_Object1__c"
and 
"Custom_Object2__c".

In the "Custom_Object2__c" I have a lookup field to "Custom_Object1__c". In "Custom_Object1__c" I have a related list with "Custom_Object2__c".
In "Custom_Object2__c" I also have a checkbox field. When changing the state of the checkbox I need in the "Custom_Object2__c" trigger to get all checked "Custom_Object2__c" records of "Custom_Object1__c".

I've implemented a code in the trigger and I'm trying to get all checked "Custom_Object2__c" records via the following query:[SELECT checkbox__c, Custom_Object2_Status__c, Id FROM Custom_Object1__c where id =:Custom_Object1_ID__c]

The issue I have is that the query returns old data which is before the update of the record.

For instance I have four out of 4 checked Custom_Object2__c records but in the trigger the query returns 3 instead of 4 checked.

How can I get the actual data?
hii,
   Am getting this error while creating suggestion box,but all fields types are correct only,don't know why its throwing this error
  Please help me to solve this.

Thanks in advance
Account and Contact has the lookup relationship. Now i want the rollup kind type of field in the Account page where i can show the count of my all contacts. I cannot change the relationship from Lookup to master- Detail.

How i will achieve this in the Account page in lookup relationship ?
I I have two custom obj one is called Parent and the other Child..lookup relationship exists between the two obj..i want to count the child records for each parent and update it in a field named "ContactsCount"..I facing some exception error when tryin to insert Child records..below is the code
trigger ConCount on Child__c (after insert) {
Set <id> CHildIds = new set<id>();
List<Child__c> ChildList = new List<Child__c>();
List<Child__c> ListCon = new List<Child__c>();
List<Parent__c> ParentList = new List <Parent__c>();
List<Parent__c> ListParent = new List <Parent__c>();
Map<id,integer> ConMap = new map <id,integer>();
if(Trigger.isInsert){
    for(Child__c Chil : Trigger.New){
    CHildIds.add(Chil.Parentlookup__c);}   
    ParentList = [select id, name from Parent__c where id IN :CHildIds];
    ChildList = [select id,name , Parentlookup__c from Child__c where Parentlookup__c IN :CHildIds];
        for(Parent__c P :ParentList){
        Listcon.clear();
        for(Child__c C : ChildList){
        if(C.Parentlookup__c == P.id){
        ListCon.add(C);
         ConMap.put(P.id,ListCon.size());
         
         } }}
        if(ParentList.size()>0){
        for(Parent__c Pa : ParentList){
        if(ConMap.size()>0){
        Pa.ContactsCount__c = ConMap.get(Pa.id);
        ListParent.add(Pa);
        }}}
        if(ListParent.size()>0)
        update ListParent;
        }}

 
I want to use place holder for date picker me using ui:inputdate
Hi All , I am facing an issue while deleting  picklist values in bulk . It is taking too  much time to delete single picklist value and if try to delete by opening in new tab it is throwing me error : There's another picklist operation in progress for this object. Try your change again later.

Can anyone please help me out as we have release this weekend and we need to deploy these picklist values after deleting few values (I need to delete almost 200 picklist values )

Thanks,
Bharat
Hi all,

Could anyone help me to matching the field with two different objects
1.I Have two objects 1.Case 2.custom object Integration__c.here i'm tring to get
the matching the some fields of both objects.

2.Case object fields for matching AccountName and IntegrationTo__c and Integration__c object fields are account__c,integrationwith__c.

3.if the both object fields are matching then get the record details from Integration__c custom object.
for that i have developed a trigger as after insert on Case object.

trigger IntegrationType on Case (after Insert) {
List<ID> cIds = new List<ID>(); //List<Integration__c> integ = new List<Integration__c>();
for(Case cObj : Trigger.new){
if(cObj.Account.Name != null && cObj.IntegrationTo__c != null){
cIds.add(cObj.Id); //add case ids.
}
}
List<Integration__c> ll = [SELECT id,name,username__c,password__c,URL__c,account__c,integrationwith__c FROM Integration__c WHERE Id=:cIds];
for(Integration__c lst : ll){
if(!cIds.isEmpty()){

//help me here how to match the fields

String uname = lst.username__c;
String pwd= lst.password__c;
String url= lst.URL__c;
System.debug('Username :' +uname);
System.debug('Username :' +pwd);
System.debug('Username :' +url);
}
}
}
How to write a salesforce formula to convert the field Date_of_Withdrawal_String__c (text) field which has he data as "2017-04-30 00:00:00" into a Date field to show the date as 30/04/2017.
I get this error: Challenge Not yet complete... here's what's wrong: 
The Suggestion custom object does not contain the correct set of custom fields. Tip: check for typos in the field names.

I've followed all steps, went back and rechecked, and then redid the entire challenge. I can't get it to pass. What am I doing wrong? I have included all custom fields and spelled them correctly.
While uploading profile picture via logged in community I want to put a validation check file size should me less than 2 mb ans type should be of JPG/JPEG and so on..I tried but not geeting through it
File to add
<apex:inputFile value="{!blbImageBody }"   id="i_file"/>
Button
<apex:commandButton value="Save" styleClass="btn-success" style="margin-right: 5px;" 
                          html-data-loading-text="Saving..." action="{!upload}"  id="i_submit" 
                          onclick="$(this).button('loading')"/>
In this line i have to perform one more jquery method that checks the validation.Kindly help me over this issue ASAP.
hi gyus... This code is working fine..when ever I insert or update record it sends email.. but I am quite confused  so plz explain me the use of line 16,line 19,line 25 & what is the use of flag... and tell me that is messaging.singleEmailMessage is defined keyword...??
Last but not the least I want to edit the code in such a way that if i insert the data with dataloader where there is more than one contact then send email to more than one contact is inserted at a time....

************apex class**********
public with sharing class HelperContactTrigger {
    public static List<Contact> sendEmail(List<Contact>Contacts)
    {
     //query on template object
        EmailTemplate et=[Select id from EmailTemplate where name=:'Sales: New Customer Email'];

        //list of emails
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();   
        
        for(Contact con : Contacts)
        {
          //check for Account
            if(con.AccountId != null && con.Email != null){

                //initiallize messaging method
                Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();

                //set object Id
                singleMail.setTargetObjectId(con.Id);

                //set template Id
                singleMail.setTemplateId(et.Id);

                //flag to false to stop inserting activity history
                singleMail.setSaveAsActivity(false);

                //add mail
                emails.add(singleMail);
            }
        }
            //send mail
        Messaging.sendEmail(emails);

        return Contacts;          
        
    }

    public static List<Contact> sendEmailafter(List<Contact>Contacts)
    {
    //query on template object
        EmailTemplate et=[Select id from EmailTemplate where name=:'Sales: New Customer Email'];

        //list of emails
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();   
        
        for(Contact con : Contacts)
        {
          //check for Account
            if(con.AccountId != null && con.Email != null){

                //initiallize messaging method
                Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();

                //set object Id
                singleMail.setTargetObjectId(con.Id);

                //set template Id
                singleMail.setTemplateId(et.Id);

                //flag to false to stop inserting activity history
                singleMail.setSaveAsActivity(false);

                //add mail
                emails.add(singleMail);
            }
         }
            //send mail
        Messaging.sendEmail(emails);

        return Contacts;          
        }
    }

*********Apex trigger********
trigger SendEmailToAccount on Contact (after insert,after update) 
{
    if(Trigger.isAfter)
    {
        if(Trigger.isInsert )
        { 
            //helper class for single email but bulk messages
            HelperContactTrigger.sendEmail(trigger.new);
        }
    }
        if(trigger.isAfter && trigger.isUpdate )
        {           
         HelperContactTrigger.sendEmailafter(trigger.new);
        }
}

 
Hi, this is related to my earlier post here

I have a fairly large test method that gives me 90% test coverage in sandbox with no problems, but then when I try to migrate it to production, I’m suddenly getting an external entry point error on the last line. I talked to my co-worker and she says it’s because there is some inconsistency between sandbox and production, but I can’t seem to figure out how to fix it. I checked all the validation rules and things like that and can’t find any inconsistencies.

Has anyone come across this before? When something works well in sandbox but then you have this sort of trouble getting it into production?