• Dushyant srivastava 8
  • NEWBIE
  • 145 Points
  • Member since 2018
  • Algoworks

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 36
    Replies
Hi could please solve this query.
i have two custom objects like company and department.If department >5 then display status is low or medium or high so please solve this

I have a custom object called "Application" and I'm trying to use a trigger to update a field on the Application record with a Case record Id when a case is created. More context....

There is an Application Number automatically created and added to a field on the Application object called "Application Number" (Application.Application_Number__c). The Case object also has a custom field called "Application Number" (Case.Application_Number__c). 

When a new Application record is created, Process Builder is invoked to create a new Case record. Process Builder takes the Application Number from my App object record and inserts it into the corresponding field on the Case record its creating. That's currently the only linked factor. 

Here's what I'm trying to accomplish with this trigger and need help with: 
I want this trigger to fire when the Case record is created, query my Application object records and look for the record with the matching Application Number (remember this is a stored value on both objects). Once it finds the record with the matching Application Number, I want to update the "Case_Id__c" field on my Application record with the actual Case record that was just created. This is so that I can relate them.

Example:
1)    Object: Application__c
          - Field: Application_Number__c
          - Field: Case_Id__c
2)  Object: Case
          - Field: Application_Number__c

I need a SOQL query to find the match via the application number, then simply update the field with the case Id.

My problem is right now I can't get this trigger to update the field and insert the Case Id. What am I doing wrong? I'm sure this is going to be a facepalm moment for me. Any help is appreciated!
 
trigger CaseRelateToApp on Case (after insert) // trigger when a new Case is created
{
    for (Case c : Trigger.new) 
    {
        String applicationNumber = c.Application_Number__c; //field on the Case holding the Application #
        String caseRecordId = c.Id;  // Case SFDC record Id

        List<Application__c> appRecord = [SELECT Id,Case_Id__c,Application_Number__c FROM Application__c WHERE Application_Number__c = :applicationNumber];  //query the Application object records and look for the matching Application Number that's stored on both object records in the field called "Application_Number__c"
       
        for(Application__c d: appRecord)
    	{
            d.Case_Id__c = caseRecordId;  //update the Case Id field on the Application object with the actual Case record Id that caused this trigger to execute.
        }
    }
}

 
Hi,
I am quite new to Salesforce. how to know the relationship between the standard object. Like what is relationship between Quote and Opportunity , Quote Line Items and Opportunity.
Hi,
I am new to integration, After learning about Apex web services and REST Apis ..
i want to know that, what is the use of writing Apex web service methods and exposing my apex class for web service(eg: @HttpGET, @HttpPOST etc..) while i can Get or Create records olny by Using URI from Workbench and set body using JSON?

thanks,
Hello All

How do i write test class for below Batch apex class, 
 
global class Emailalertbatchclass implements Database.Batchable<sObject>, Schedulable, Database.Stateful {
    
    //Variable Section
    global FINAL String strQuery;
    global FINAL String leadid;
    global List<String> errorMessages = new List<String>();
    
    global Emailalertbatchclass() { 
        this.strQuery = getBatchQuery();
    }
    
    //Returns the Query String to Batch constructor to fetch right records.
    private String getBatchQuery() {
        String strQuery = 'SELECT Id,Name,Status,Email,owner.email,owner.name,ownerid,No_Enquiry_Email_Sent__c,Manager_Email__c FROM Lead where No_Enquiry_Email_Sent__c=false AND Status=\'Enquiry\' And (CreatedDate = YESTERDAY OR LastModifiedDate = YESTERDAY) limit 1';
        return strQuery;
    }
    
    //Batch Start method
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(strQuery);
    }
    
    //Batch Execute method calls findCostForWoD method
    global void execute(Database.BatchableContext BC, List<sObject> scopeList) {
        System.debug(LoggingLevel.INFO, '== scopeList size ==' + scopeList.size());
        
        List<Lead> ld = (List<Lead>) scopeList;
        List<Lead> updatedld = new List<Lead>();
        if(!ld.isEmpty()) { 
            List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
            for (Lead prod : ld)
            {               
                // Step 1: Create a new Email
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                
                // Step 2: Set list of people who should get the email
                String[] toAddresses = new String[] {prod.owner.Email,prod.Manager_Email__c,'chandra.s@proseraa.com'};
                    mail.setToAddresses(toAddresses);
                
                // Step 3: Set who the email is sent from
                mail.setReplyTo(prod.owner.Email);
                mail.setSenderDisplayName('No Activity on Leads for 24hrs');
                
                // (Optional) Set list of people who should be CC'ed
                List<String> ccTo = new List<String>();
                ccTo.add('manjunath.s@proseraa.com');
                mail.setCcAddresses(ccTo);
                
                // Step 4. Set email contents - you can use variables!
                mail.setSubject('No Activity on Lead for 24hrs');
                String body = 'Dear ' + prod.owner.name + ', <br><br>';
                body += 'This is to notify you that there is no activity done on the respective <b> Lead Name: ';
                body +=prod.Name+'</b>  please find the link below..<br><br>';
                body += 'link to file: https://moengage--proseraa.lightning.force.com/lightning/r/Lead/'+prod.id+'/view'+'<br><br><br> Thanks,<br>Moengage Team</body></html>';
                mail.setHtmlBody(body);
                
                // Step 5. Add your email to the master list
                mailList.add(mail);
                prod.No_Enquiry_Email_Sent__c = true;
                updatedld.add(prod);
                
            }
            if(!mailList.isEmpty()) {
                try{
                    Messaging.sendEmail(mailList);
                    update updatedld;
                }
                catch (Exception ex) {
                    errorMessages.add('Unable to send email to Tech: '+ ex.getStackTraceString());
                }
            }
        }
    }  
    
    //Batch Finish method for after execution of batch work
    global void finish(Database.BatchableContext BC) { 
        
    }
    
    //Method which schedules the ProductDownloadBatch
    global void execute(SchedulableContext sc) {        
        Emailalertbatchclass snInstance = new Emailalertbatchclass();
        ID batchprocessid = Database.executeBatch(snInstance);
    }
}

 
Hi,

I was trying to redirect a VF to New Custom Field Page and i figured out that "www.{baseurl}/p/setup/field/NewCustomFieldStageManager?entity={enitity ID}" is the URL. BUt not able to understand what exactly is Entity here for Standard objects it there API name i guess but not sure what its for Cutsom object because there is a 15 digit id when you see it.

Anyone knows what enitity id is and how to get that or how to redirect to the page attached bellow in an image, Please let me know that will be a great help.Entity
Hi All,

Is it possible to create related list records to an custome object(look up relation) of a Opportunity object when ever the status field in opportunity updated and matches the criteria?

when ever opportunity stages= Booked then it should create a new record (custom object) and update the related opportunity to it?

Please help me if anyone have idea on such scenerio.

Thanks,
Supriya
How to show the records to Rhonda wheeler which is created by mark smith i.e midwest clost lost opportunities report.
Rhonda wheeler is not able to see the records in side the report .even though she has an access to the public report .
Hello Team ,

I am facing issue not getting the record type in soqlQuery
User-added image

System.debug('------------>'+SchemeApplicablefor);
        System.debug('------------>'+samid);
        Set<String> RTNames = new Set<String>();
        
        if(SchemeApplicablefor == 'Distributer'){
            RTNames.add('India SND');
            RTNames.add('Brand W');
            RTNames.add('H&H Modern Trade Distributor');
            RTNames.add('H&H Traditional Trade Distributor');
        }
        if(SchemeApplicablefor == 'Retailer'){
            RTNames.add('H&H Modern Trade Retailer');
            RTNames.add('H&H Traditional Trade Retailer');
            RTNames.add('India SND Retailer');
            RTNames.add('Brand W Retailer');
        }
        if(SchemeApplicablefor == 'Both'){
            RTNames.add('India SND');
            RTNames.add('Brand W');
            RTNames.add('H&H Modern Trade Distributor');
            RTNames.add('H&H Traditional Trade Distributor');
            RTNames.add('H&H Modern Trade Retailer');
            RTNames.add('H&H Traditional Trade Retailer');
            RTNames.add('India SND Retailer');
            RTNames.add('Brand W Retailer');
        }
        
        String soqlQuery = 'SELECT Id, Name, RecordType.Name FROM Account where RecordType.Name in:RTNames';
        System.debug('soqlQuery@@'+soqlQuery);

Please help me to solve the issue.
Hi could please solve this query.
i have two custom objects like company and department.If department >5 then display status is low or medium or high so please solve this

I have a custom object called "Application" and I'm trying to use a trigger to update a field on the Application record with a Case record Id when a case is created. More context....

There is an Application Number automatically created and added to a field on the Application object called "Application Number" (Application.Application_Number__c). The Case object also has a custom field called "Application Number" (Case.Application_Number__c). 

When a new Application record is created, Process Builder is invoked to create a new Case record. Process Builder takes the Application Number from my App object record and inserts it into the corresponding field on the Case record its creating. That's currently the only linked factor. 

Here's what I'm trying to accomplish with this trigger and need help with: 
I want this trigger to fire when the Case record is created, query my Application object records and look for the record with the matching Application Number (remember this is a stored value on both objects). Once it finds the record with the matching Application Number, I want to update the "Case_Id__c" field on my Application record with the actual Case record that was just created. This is so that I can relate them.

Example:
1)    Object: Application__c
          - Field: Application_Number__c
          - Field: Case_Id__c
2)  Object: Case
          - Field: Application_Number__c

I need a SOQL query to find the match via the application number, then simply update the field with the case Id.

My problem is right now I can't get this trigger to update the field and insert the Case Id. What am I doing wrong? I'm sure this is going to be a facepalm moment for me. Any help is appreciated!
 
trigger CaseRelateToApp on Case (after insert) // trigger when a new Case is created
{
    for (Case c : Trigger.new) 
    {
        String applicationNumber = c.Application_Number__c; //field on the Case holding the Application #
        String caseRecordId = c.Id;  // Case SFDC record Id

        List<Application__c> appRecord = [SELECT Id,Case_Id__c,Application_Number__c FROM Application__c WHERE Application_Number__c = :applicationNumber];  //query the Application object records and look for the matching Application Number that's stored on both object records in the field called "Application_Number__c"
       
        for(Application__c d: appRecord)
    	{
            d.Case_Id__c = caseRecordId;  //update the Case Id field on the Application object with the actual Case record Id that caused this trigger to execute.
        }
    }
}

 
Goal is to link opportunities with a Contact.  Opportunity is associated with 1 Contact, but for different locations. 1 Contact who is associated with the 'parent' account, but opportunities are associated with their other locations.
hi Everyone,
I have created a trigger on the quote to set billing contact
if contact is not available it will create a new contact also I have a duplicate rule enabled on the contact, Alert and Report  checkbox is true for on create and on edit
Contact c = new Contact();
                            c.FirstName = newQuotes[i].Billing_Contact_First_Name__c;
                            c.LastName = newQuotes[i].Billing_Contact_Last_Name__c;
                            c.Email = newQuotes[i].Billing_Contact_Email__c;
                            c.AccountId = oppMap.get(newQuotes[i].SBQQ__Opportunity2__c).AccountId;
                            c.Title = newQuotes[i].Billing_Contact_Title__c;
                            c.Phone = newQuotes[i].Billing_Contact_Phone__c;
                            c.Billing_Contact__c = TRUE;
                            
                            //bypass duplicates
                            Database.DMLOptions dml = new Database.DMLOptions(); 
                            dml.DuplicateRuleHeader.allowSave = true;
                            dml.DuplicateRuleHeader.runAsCurrentUser = true;
                            Database.SaveResult sr = Database.insert(c, dml);
                            if (sr.isSuccess()) {
                                System.debug('Duplicate COntact has been inserted in Salesforce!');
                            }else{
                                System.debug(sr);
                            }
but the bypass is not working else part is still throwing error
[142]|DEBUG|Database.SaveResult[getErrors=(Database.Error[getFields=();getMessage=<!-- DupeBlocker blocked this action - duplicates found. --> <div style="padding:0.7em;font-size:11px;width:40em;margin:0 auto;background-color:#FBF9EE;border-color:#FCEFA1;border-width:1px;border-style:solid;border-radius:4px;">
is there any solution for trigger to bypass duplicate rule
Thanks 
Rahul
I have written a custom Apex rest api, that will create and update lead in salesforce. Whenever the api is called from external system, salesforce will get a json file which will have lead deatails and email id. If the email id already exists in salesforce it will update the lead. Else create a new one.
Whenever there is some 2 or more requests call at same time and it is lead creation requests, both requests are inserting the leads. This creates the duplicate lead.
We can enable duplicate rule, but it will not process another request. I want to process all requests without skipping any requests.
Do you have solution for this issue

Thanks
Hi Developers

i am working on  the test class for Emailalertbatclass, but i am not able to cover the excute method, it is only showing 27%, could anyone please help in the covering 100%
 
global class Emailalertbatchclass implements Database.Batchable<sObject>, Schedulable, Database.Stateful {
    
    //Variable Section
    global FINAL String strQuery;
    global FINAL String leadid;
    global List<String> errorMessages = new List<String>();
    
    global Emailalertbatchclass() { 
        this.strQuery = getBatchQuery();
    }
    
    //Returns the Query String to Batch constructor to fetch right records.
    private String getBatchQuery() {
        String strQuery = 'SELECT Id,Name,Status,Email,owner.email,owner.name,ownerid,No_Enquiry_Email_Sent__c,Manager_Email__c,recordtype.name FROM Lead where No_Enquiry_Email_Sent__c=false AND recordtype.name=\'Lead Registration\' AND Lead_Intent_Type__c=\'High Intent Lead\' AND Status=\'Enquiry\' And ((DaysSinceLastActivityDone__c>=0) OR (DayssinceEnquirystage__c >= 0))';
        return strQuery;
    }
    
    //Batch Start method
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(strQuery);
    }
    
    //Batch Execute method calls findCostForWoD method
    global void execute(Database.BatchableContext BC, List<sObject> scopeList) {
        System.debug(LoggingLevel.INFO, '== scopeList size ==' + scopeList.size());
        
        List<Lead> ld = (List<Lead>) scopeList;
        List<Lead> updatedld = new List<Lead>();
        if(!ld.isEmpty()) { 
            List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
            for (Lead prod : ld)
            {               
                // Step 1: Create a new Email
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                System.debug( 'prod.owner.Email ' + prod.owner.Email);
                String[] toAddresses = new String[] {prod.owner.Email};
                    // Step 2: Set list of people who should get the email
                    if(prod.Manager_Email__c!=null && prod.Manager_Email__c==''){
                        toAddresses.add(prod.Manager_Email__c);
                    }
                mail.setToAddresses(toAddresses);
                System.debug( 'toAddresses ' + toAddresses);
                
                // Step 3: Set who the email is sent from
                mail.setReplyTo(prod.owner.Email);
                mail.setSenderDisplayName('No Activity on Leads for 24hrs');
                
                // (Optional) Set list of people who should be CC'ed
                List<String> ccTo = new List<String>();
                mail.setCcAddresses(ccTo);
                
                // Step 4. Set email contents - you can use variables!
                mail.setSubject('No Activity on Lead for 24hrs');
                String body = 'Dear ' + prod.owner.name + ', <br><br>';
                body += 'This is to notify you that there is no activity done on the respective <b> Lead Name: ';
                body +=prod.Name+'</b>  please find the link below..<br><br>';
                body += 'link to file: '+URL.getSalesforceBaseUrl().toExternalForm()+'/'+prod.id+'<br><br><br> Thanks,<br>Moengage Team</body></html>';
                mail.setHtmlBody(body);
                System.debug( 'body ' + body);
                
                // Step 5. Add your email to the master list
                mailList.add(mail);
                prod.No_Enquiry_Email_Sent__c = true;
                updatedld.add(prod);
                System.debug( 'prod ' + prod);
                
            }
            if(!mailList.isEmpty()) {
                try{
                    Messaging.sendEmail(mailList);
                    update updatedld;
                    system.debug('mailList '+mailList);
                }
                catch (Exception ex) {
                    errorMessages.add('Unable to send email to Tech: '+ ex.getStackTraceString());
                }
            }
        }
    }  
    
    //Batch Finish method for after execution of batch work
    global void finish(Database.BatchableContext BC) { 
        
    }
    
    //Method which schedules the ProductDownloadBatch
    global void execute(SchedulableContext sc) {        
        Emailalertbatchclass snInstance = new Emailalertbatchclass();
        ID batchprocessid = Database.executeBatch(snInstance);
    }
}

Test Class
 
@isTest
public class EmailalertbatchclassTestclass
{
    static testMethod void testmethod1()
    {
        
        Id rcdTypeId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Lead Registration').getRecordTypeId();
        List<Lead> Leadld = new List<Lead>();
        lead ld = new lead();
        ld.FirstName= 'test';
        ld.LastName='Test2';
        ld.status='Enquiry';
        ld.Company = 'fgfh';
        ld.Email = 'Nilu112@gmail.com';
        ld.Manager_Email__c = 'rakeshkumar1998@gmail.com';
        ld.RecordTypeId = rcdTypeId;//added here
        ld.No_Enquiry_Email_Sent__c = false;  //changed true to false
        
        Insert ld;
        Leadld.add(ld); 
        
        Test.startTest();
        ld.FirstName = 'test1';
        update ld;
        
        Emailalertbatchclass snInstance = new Emailalertbatchclass();
        ID batchprocessid = Database.executeBatch(snInstance);
        
        Test.stopTest();
    }
    public static testMethod void testschedule() {
        Test.StartTest();
        Emailalertbatchclass sh1 = new Emailalertbatchclass();
        String sch = '0 00 01 * * ?'; 
        ID batchprocessid = Database.executeBatch(sh1);
        String jobId = system.schedule('Emailalertbatchclass', sch, sh1);
        System.assert(jobId != null);
        Test.stopTest(); 
    }
}

 
In our org when the Account is changed on the Contact Record, we want the Contact record type to update depending on the record type of the Account along with some other conditions.

We have workflow rules in place currently that get the job done but we are trying to get away from the workflow rules.

We tried Process Builder to do this but since it is not bulkified we kept receiving Apex CPU limit errors when doing bulk updates.

Has anyone implemented this or something like it using Flow? 

Thanks for any help.

I have a Webservice which sends me transactions. We want to track the changes record by record just as a Bank Statement. We are using webservice to store Credit and Debit amount.

In the trigger we are quering for the last record [I know this is not what best practice says, but was not able think of a better way] and then calculating the balance for this record.

trigger:

trigger ASM_Balance on Assembly_Transactions__c (before insert) {
    
    List<Assembly_Transactions__c> trans = [SELECT ID, balance__c FROM Assembly_Transactions__c WHERE Wallet_Owner__c =: Trigger.new[0].Wallet_Owner__c ORDER BY CreatedDate DESC LIMIT 1];
    
    Double balance = 0;
    if(trans.size()>0)
    {
        if(trans[0].balance__c != null)
            balance = trans[0].balance__c;
    }
    Assembly_Transactions__c tr = Trigger.new[0];
    Double cr = tr.credit__c;
    Double dt = tr.debit__c;
    Double amount = balance+cr-dt;
    tr.balance__c = amount;
}

The error occours when we have two transactions at the same time, and the webservice is hit back to back. 

I think this is due to SOQL being run just before we have the last transaction inserted successfully. 

Please help me out with suggestions.

Hello All

i need a small help, i am trying to design an apex batch class where when lead is not modified for more than 24Hrs, Then Automatically email should fire to  lead owner and lead owners email address, For lead owner emaill address, i have created a process builder where lead owners manager email is populated when lead is newly created, i tried this with workflow and Timebased workflow rule, but still not working properly

Below is my Batch apex class
 
global class Emailalertbatchclass implements Database.Batchable<sObject>, Schedulable, Database.Stateful {
    
    //Variable Section
    global FINAL String strQuery;
    global FINAL String leadid;
    global List<String> errorMessages = new List<String>();
    
    global Emailalertbatchclass() { 
        this.strQuery = getBatchQuery();
    }
    
    //Returns the Query String to Batch constructor to fetch right records.
    private String getBatchQuery() {
        String strQuery = 'SELECT Id,Name,Status,Email,owner.email,owner.name,ownerid,No_Enquiry_Email_Sent__c,Manager_Email__c FROM Lead where No_Enquiry_Email_Sent__c=false AND Status=\'Enquiry\' And (CreatedDate = YESTERDAY OR LastModifiedDate = YESTERDAY) limit 1';
        return strQuery;
    }
    
    //Batch Start method
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(strQuery);
    }
    
    //Batch Execute method calls findCostForWoD method
    global void execute(Database.BatchableContext BC, List<sObject> scopeList) {
        System.debug(LoggingLevel.INFO, '== scopeList size ==' + scopeList.size());
        
        List<Lead> ld = (List<Lead>) scopeList;
        List<Lead> updatedld = new List<Lead>();
        if(!ld.isEmpty()) { 
            List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
            for (Lead prod : ld)
            {               
                // Step 1: Create a new Email
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                
                // Step 2: Set list of people who should get the email
                String[] toAddresses = new String[] {prod.owner.Email,prod.Manager_Email__c,'chandra.s@proseraa.com'};
                    mail.setToAddresses(toAddresses);
                
                // Step 3: Set who the email is sent from
                mail.setReplyTo(prod.owner.Email);
                mail.setSenderDisplayName('No Activity on Leads for 24hrs');
                
                // (Optional) Set list of people who should be CC'ed
                List<String> ccTo = new List<String>();
                ccTo.add('manjunath.s@proseraa.com');
                mail.setCcAddresses(ccTo);
                
                // Step 4. Set email contents - you can use variables!
                mail.setSubject('No Activity on Lead for 24hrs');
                String body = 'Dear ' + prod.owner.name + ', <br><br>';
                body += 'This is to notify you that there is no activity done on the respective <b> Lead Name: ';
                body +=prod.Name+'</b>  please find the link below..<br><br>';
                body += 'link to file: https://moengage--proseraa.lightning.force.com/lightning/r/Lead/'+prod.id+'/view'+'<br><br><br> Thanks,<br>Moengage Team</body></html>';
                mail.setHtmlBody(body);
                
                // Step 5. Add your email to the master list
                mailList.add(mail);
                prod.No_Enquiry_Email_Sent__c = true;
                updatedld.add(prod);
                
            }
            if(!mailList.isEmpty()) {
                try{
                    Messaging.sendEmail(mailList);
                    update updatedld;
                }
                catch (Exception ex) {
                    errorMessages.add('Unable to send email to Tech: '+ ex.getStackTraceString());
                }
            }
        }
    }  
    
    //Batch Finish method for after execution of batch work
    global void finish(Database.BatchableContext BC) { 
        
    }
    
    //Method which schedules the ProductDownloadBatch
    global void execute(SchedulableContext sc) {        
        Emailalertbatchclass snInstance = new Emailalertbatchclass();
        ID batchprocessid = Database.executeBatch(snInstance);
    }
}

and Below is my schedular class
 
global class Scheduleerclassemailalert implements Schedulable
{
    global void execute(SchedulableContext SC) { 
         Emailalertbatchclass snInstance = new Emailalertbatchclass();
        ID batchprocessid = Database.executeBatch(snInstance); }
}
so how do i resolve this issue??
 
Hi,
I am quite new to Salesforce. how to know the relationship between the standard object. Like what is relationship between Quote and Opportunity , Quote Line Items and Opportunity.