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

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 21
    Replies
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);
    }
}

 
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??
 
do event publishing to "platform event" via RestAPI consume org's API limits?

Test class !!!!!

public class UploadController { 
    
    public class MainWrapper {
        @AuraEnabled public List<ColumnWrapper> ColumnWrap{get;set;}
        @AuraEnabled public List<DocWrap> lstContentDocument{get;set;}
        
        public MainWrapper(List<ColumnWrapper> lstColumnWrapper, List<DocWrap> lstContentDocument){
            this.lstColumnWrapper = lstColumnWrapper;
            this.lstContentDocument = lstContentDocument; 
        }
    }
    public class DocWrapper {
        @AuraEnabled public String strBase64{get;set;}
        @AuraEnabled public String strContentType{get;set;}
        
        public DocWrapper(String strBase64, String strContentType){
            this.strBase64 = strBase64;
            this.strContentType = strContentType; 
        }
    } 
    public class DocWrap {
        @AuraEnabled public String Id{get;set;}
        @AuraEnabled public String Title{get;set;}
        @AuraEnabled public String CreatedDate{get;set;}
        @AuraEnabled public String FileType{get;set;}
        @AuraEnabled public String FileExtension{get;set;}
        @AuraEnabled public String ContentSize{get;set;} 
        @AuraEnabled public Boolean isInSFDC{get;set;}
        
        public DocWrap(String Id, String Title, String CreatedDate, String FileType, String FileExtension, String ContentSize, Boolean isInSFDC){
            this.Id = Id;
            this.Title = Title; 
            this.Id = Id;
            this.CreatedDate = CreatedDate; 
            this.FileType = FileType;
            this.FileExtension = FileExtension; 
            this.ContentSize = ContentSize;            
            this.isInSFDC = isInSFDC;
        }
    }
    
    public class ColumnWrapper {
        @AuraEnabled public String label {get;set;}
        @AuraEnabled public String fieldName {get;set;}
        @AuraEnabled public String type {get;set;} 
        @AuraEnabled public Boolean sortable {get;set;}  
        @AuraEnabled public SubColumnWrapper typeAttributes {get;set;}
        
        public ColumnWrapper(string label, String fieldName,string type, Boolean sortable, SubColumnWrapper typeAttributes){
            this.label = label;
            this.fieldName = fieldName;
            this.type = type; 
            this.sortable = sortable;  
            this.typeAttributes = typeAttributes;
        }
        public ColumnWrapper(string label, String fieldName,string type, Boolean sortable){
            this.label = label;
            this.fieldName = fieldName;
            this.type = type; 
            this.sortable = sortable;   
        }
    }
    
    //typeAttributes: { label: 'View Details', name: 'view_details', title: 'Click to View Details'}
    public class SubColumnWrapper {
        @AuraEnabled public String label {get;set;}
        @AuraEnabled public String name {get;set;}
        @AuraEnabled public string title {get;set;}  
        
        public SubColumnWrapper(){
        }
        
        public SubColumnWrapper(string label, String name,string title){
            this.label = label;
            this.name = name;
            this.title = title;  
            
        }
    } 
    @AuraEnabled    
    public static string getContent(String strMime){
        List<Document_Mime_Types__mdt> lst = new List<Document_Mime_Types__mdt>();
        lst = [SELECT Id, Content_Type__c, Mime_Type__c FROM Document_Mime_Types__mdt WHERE Mime_Type__c =: strMime];
        if(lst.size() > 0)
            return lst[0].Content_Type__c;
        else
            return null;
    }
    @AuraEnabled
    public static DocWrapper ValidateDoc(String strContentDocumentId, Boolean onSalesforce) { 
        //System.debug('ContentDocumentId'+strContentDocumentId);
        ContentVersion obj = new ContentVersion();
        
        if(onSalesforce) 
        {
            obj = [SELECT FileType, FileExtension ,CreatedDate,VersionData FROM ContentVersion WHERE ContentDocumentId =: strContentDocumentId];
            //System.debug('obj.VersionData : '+obj.VersionData);
        }
        
        
        else{
            final string Folder = '/'+ strContentDocumentId;
            System.HttpResponse res = makeCallout(Folder, 'DR_Documents');
            if(res.getStatusCode() == 200 || res.getStatusCode() == 201){
                // Parsing Code 
                System.debug('res.getBody())'+res.getBody());
                String str =  res.getBody().substringAfter('{"documents":[');
                //System.debug('res.g '+str);
                str = str.substringBefore(']}'); 
                Map<String, Object> m1 = (Map<String, Object>)JSON.deserializeUntyped(str);
                //System.debug('Map'+m1);
                
                //System.debug('String.valueOf(m1.get())'+String.valueOf(m1.get('mimeType')));
                
                String strmime = getContent(String.valueOf(m1.get('mimeType')));
                
                //System.debug('Sstr1 mimeType'+ strmime);
                
                if(String.isblank(strmime))
                {
                    
                    return new DocWrapper( String.valueOf(m1.get('content')), String.valueOf(m1.get('mimeType'))); 
                }
                else   
                {
                    
                    return new DocWrapper( String.valueOf(m1.get('content')), strmime); 
                }
                
            }
        }   
        String str112 = getContent(obj.FileExtension); 
        
        if(String.isBlank(str112)){ 
            return new DocWrapper(EncodingUtil.base64Encode(obj.VersionData), obj.FileExtension);
            
        }
        else  {    
           
            return new DocWrapper(EncodingUtil.base64Encode(obj.VersionData), str112); 
            
        }
    }
    
    @AuraEnabled
    public static MainWrapper getRecordLocal(String strCaseId) {   
        List<ContentDocumentLink> lstContentDocumentLink = new List<ContentDocumentLink>();
        List<ColumnWrapper> lstColumnWrapper = new List<ColumnWrapper>();
        List<DocWrap> lstDocWrap = new List<DocWrap>(); 
        Set<ID> setId = new Set<ID>(); 
        Set<ID> setEmailMessageId = new Set<ID>(); 
        
        for(EmailMessage objEmailMessage : [SELECT Id FROM EmailMessage WHERE ParentId =: strCaseId])
            setEmailMessageId.add(objEmailMessage.Id);
        setEmailMessageId.add(strCaseId);         
        lstContentDocumentLink =   [SELECT ContentDocumentId FROM ContentDocumentLink 
                                    WHERE LinkedEntityId =: setEmailMessageId ];  
        
        for(ContentDocumentLink objContentDocumentLink : lstContentDocumentLink)
            setId.add(objContentDocumentLink.ContentDocumentId);  
        
        for(ContentDocument objContentDocument :[SELECT Id, Title, CreatedDate, FileType, FileExtension, ContentSize FROM ContentDocument WHERE Id =: setId Order by CreatedDate DESC]){
            String size = '';  
            if(objContentDocument.ContentSize/1024 < 1024)
                size =  String.valueOf(objContentDocument.ContentSize / 1024) + ' KB';
            else                                       
                size =  String.valueOf(objContentDocument.ContentSize / 1048576 ) + ' MB';
            lstDocWrap.add(new DocWrap(String.valueOf(objContentDocument.Id), objContentDocument.Title,  String.valueOf(objContentDocument.CreatedDate), objContentDocument.FileType, objContentDocument.FileExtension, size, true ));
        } 
        lstColumnWrapper.add(new ColumnWrapper('Title', 'Title', 'text' , true ));
        lstColumnWrapper.add(new ColumnWrapper('Created Date', 'CreatedDate', 'datetime' , true));
        lstColumnWrapper.add(new ColumnWrapper('Type', 'FileType', 'text' , true ));
        lstColumnWrapper.add(new ColumnWrapper('View Document', 'Id', 'button' , false , new SubColumnWrapper('View', 'View Document','View Document')));            
        
        if(lstDocWrap.isEmpty())
        {
            return new MainWrapper(lstColumnWrapper, lstDocWrap); }
        else{
            return new MainWrapper(lstColumnWrapper, lstDocWrap);}
    }
    
    @AuraEnabled
    public static List<DocWrap> getRecord(String strCaseId) {    
        //system.debug('strCaseId'+strCaseId);
        List<DocWrap> lstDocWrap = new List<DocWrap>();  
        try{
            String metaDeveloperName = '';
            string Folder = '';
            Case objCase = [SELECT CaseNumber,C_Case_Id__c, Document_Id__c,document_number__c FROM Case WHERE ID =: strCaseId LIMIT 1];
            
 
            if(objCase.document_number__c !=''){
                metaDeveloperName = 'DCN_Documents';
                 Folder = '?metadataValues=' + objCase.document_number__c +'&metadataNames=DCN%20Id&category=ESAWS%20-%20Model&subCategory=Intake';
             }
            else{
                metaDeveloperName = 'DR_Documents';
                Folder = '?category=ESAWS%20-%20Model&subCategory=Documents&metadataNames=Case%20Id&metadataValues='+ objCase.CaseNumber;
              }
                
             
            System.HttpResponse res = makeCallout(Folder,metaDeveloperName);
           // System.debug('response'+res);
            String ResponseBody;
            Map<String, Object> m = new Map<String, Object>();
            System.debug('res.getStatusCode()  Before'+res.getStatusCode() );
            if(res.getStatusCode() == 200 || res.getStatusCode() == 201){
                // Parsing Code  
                ResponseBody = res.getBody(); 
                
                for(MS_parseJSON.cls_documents objcls_documents : MS_parseJSON.parse(res.getBody()).documents ){
                    lstDocWrap.add(new DocWrap(objcls_documents.id, objcls_documents.name, objcls_documents.createdOn, objcls_documents.mimeType , objcls_documents.mimeType ,' ' ,false ));
                } 
            }   
            
            if(objCase.C_Case_Id__c != null ){
                
                final string str_C_Folder = '?category=ESAWS%20-%20Model&subCategory=Documents&metadataNames=Case%20Id&metadataValues='+ objCase.C_Case_Id__c;
                System.HttpResponse resCA = makeCallout(str_C_Folder,metaDeveloperName);
                
                String ResponseBodyCA;
                Map<String, Object> m1 = new Map<String, Object>(); 
                if(resCA.getStatusCode() == 200 || resCA.getStatusCode() == 201){
                    // Parsing Code  
                    ResponseBodyCA = resCA.getBody(); 
                    
                    for(MS_parseJSON.cls_documents objcls_documents : MS_parseJSON.parse(resCA.getBody()).documents ){
                        lstDocWrap.add(new DocWrap(objcls_documents.id, objcls_documents.name, objcls_documents.createdOn, objcls_documents.mimeType , objcls_documents.mimeType ,' ' ,false ));
                    } 
                }  
            }
              if(objCase.Document_Id__c != null){
                List<String> lstDocIds = new List<String>();
                lstDocIds = objCase.Document_Id__c.split(',');
                for(String strId : lstDocIds){ 
                    final string Folder1 = '/'+ strId;
                    System.HttpResponse res1 = makeCallout(Folder1,metaDeveloperName );
                    system.debug('res1'+res1);
                    if(res1.getStatusCode() == 200 || res1.getStatusCode() == 201){
                        // Parsing Code 
                        for(MS_parseJSON.cls_documents objcls_documents : MS_parseJSON.parse(res1.getBody()).documents )
                            lstDocWrap.add(new DocWrap(objcls_documents.id, objcls_documents.name, objcls_documents.createdOn, objcls_documents.mimeType , objcls_documents.mimeType ,' ' ,false ));
                     }
                }
            } 
        }
        catch(Exception vEx){
            system.debug('vEx'+vEx);
            EHSerExceptionLogUtilityClass.CreateException(vEx); 
        }
        if(!lstDocWrap.isEmpty())
            return lstDocWrap;  
        return null; 
        
    } 
    
    public static System.HttpResponse makeCallout(String Folder,String metaDeveloperName){
        
        system.Debug('Folder'+Folder);
        system.Debug('metaDeveloperName'+metaDeveloperName);
        // Http instance
        HttpRequest ObjRequest = new HttpRequest(); 
        Http ObjHTTp = new Http();
        List<String> lstRequestBody = new List<String>();
        //Final data 
        final string Content_Type = 'application/json';   
        
        final string On_CRED = 'DMS Credentials';
        final string strMethod = 'GET';
        ObjRequest = EUploadController.MakeRequest(metaDeveloperName, Folder, strMethod, On_CRED ); 
        System.HttpResponse res;
        try{ 
            res = ObjHTTp.send(ObjRequest); 
        } 
        catch(Exception vEx){
            EHSerExceptionLogUtilityClass.CaptureAPIResponse(res.getStatusCode() + res.getBody() + 'UploadController');
        }
        system.debug('res1'+res.getBody());
        System.debug('Status code'+res.getStatusCode() );
        if(res.getStatusCode() == 200 || res.getStatusCode() == 201)
            return res; 
        else
            EHSerExceptionLogUtilityClass.CaptureAPIResponse(res.getStatusCode() + res.getBody() + 'UploadController');  
        return res;
    }
}

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,
Hi getting error when trying to delete a recourd wher record owner != logged in user below is my code 

trigger MobDiscount on Mobile__c (before insert,before update,before delete) {
Trigger :     
    if(Trigger.isinsert == true)
    {
        DiscountForMobiles.DiscountNewCoustomer(Trigger.new);
    }
    
    if(Trigger.isupdate == true)
    {
        DiscountForMobiles.DiscountOldCoustomer(Trigger.new);
    }
    
    if(Trigger.isdelete == true && Trigger.isbefore == true)
    {
        DiscountForMobiles.OwnwerAloneCanDelete(Trigger.old);
    }
    
}

Apex Class :

public class DiscountForMobiles {
    
    Public Static Void DiscountNewCoustomer(List<Mobile__c> CoustomerList)
    {
        for(Mobile__c SingleCoustomer : CoustomerList ){
            
            If(SingleCoustomer.Brand__c == 'Samsung')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c * 10/100;
               SingleCoustomer.Discount_Status__c = '10 % Discount';
            }
            
            if(SingleCoustomer.Brand__c == 'Apple')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c - SingleCoustomer.Price__c * 5/100;
               SingleCoustomer.Discount_Status__c = '5 % Discount';
            }
            
        }
        
    }

    Public Static Void DiscountOldCoustomer(List<Mobile__c> CoustomerList)
    {
        for(Mobile__c SingleCoustomer : CoustomerList ){
            
            If(SingleCoustomer.Brand__c == 'Samsung')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c - SingleCoustomer.Price__c * 10/100;
               SingleCoustomer.Discount_Status__c = '5 % Discount';
            }
            
            If(SingleCoustomer.Brand__c == 'Apple')
            {
                
               SingleCoustomer.Price__c = SingleCoustomer.Price__c * 5/100;
               SingleCoustomer.Discount_Status__c = 'NO Discount';
            }
            
        }
        
    }
    Public Static Void OwnwerAloneCanDelete(List<Mobile__c> CoustomerList)
    {
        
        for(Mobile__c Costomer : CoustomerList)
        {
            If(Costomer.OwnerId != Userinfo.getUserId())
            {
                Costomer.adderror('only owner can delete');
            }
        }
         
    }
      
}
Create a list custom setting named “Country”. Create four records of this custom setting:
1. Name = India
2. Name = France
3. Name = Italy
4. Name = USA
Create another list custom setting named “City”. Add a field “Country” of data type text on this
custom setting.
Create following records of this custom setting:
1. Name = New Delhi, Country = India
2. Name = Mumbai, Country = India
3. Name = Pu ne, Country = India
4. Name = Kolkata, Country = India
5. Name = Ney York, Country = USA
6. Name = Miami, Country = USA
7. Name = Washington DC, Country = USA
8. Name = Paris, Country = France
9. Name = Lyon, Country = France
10. Name = Milan, Country = Italy
11. Name = Rome, Country = Italy

Create a Visual Force page. This page should display two picklists, one for Country and another for City. Initially city picklist should not display any value; instead, it should be dependent upon Country picklist. So when the user selects a particular country then City picklist should load all the cities corresponding to the selected country.

plz help in this question i have created 2 custom setting name as city and country but i am stuck in vf page plz any one help me 
thank you 
Hello, 

We are looking to automate Permission Sets Administrative activity, As part of this we are planning to build an Generic API to access/grant the Permission Sets. Please advise. 

I have data from external data warehouse pushing data through Skyvia to Salesforce. It will upsert Contacts. However, I want to know how to have the process check if there is any existing lead with same email then convert that lead to a Contact then update that same Contact. 

Right now, our salespeople have to keep manually check if the Contact got created in Salesforce then they will need to go to the lead and manually convert and then choose the matching Contact. This needs to (and I know it can be) automated!

 

How can I achieve that? 

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

 
I have inherited a lot of old code which uses @future methods for doing DML operations. Is there any benefit to doing this? The only thing I can think of is in case there are a lot of records to be updated but I thought @future methods were only really used for callouts.
 
Hello guys!

If Salesforce language is not English, I have some problems with response from REST API.

For example, if Salesforce language is English than I get a response in English and it's good for me cause I can handle this error and fix it
[
    {
        "message": "test, test does not have an accessible email address.",
        "errorCode": "INVALID_EMAIL_ADDRESS",
        "fields": [
            "CcAddress"
        ]
    }
]

But if our user uses the French language like main Salesforce`s language, then we have some problems with response
[
    {
        "message": "test, test n'a pas d'adresse e-mail accessible.",
        "errorCode": "INVALID_EMAIL_ADDRESS",
        "fields": [
            "CcAddress"
        ]
    }
]

We need to have a response error message in English for success handling errors from REST API.

I try to use Accept-Language header, but it did not work for me.

I don't want to write "flexible solutions" like "if" for separated language  to solve this issue.

Can you help me with it?
 
Hey there,

when writing Trigger Handler Classes and calling the respective methods from a Master Trigger there are different ways to achieve this. The keywords are Static and Non-Static .

In other words:
public void
vs.
public static void
I was wondering what's the best practice to write and call a method from a Master Trigger. In fact both options will work - but I once read that going for non-static was always the better choice. Why is that?

Given we have a method in our class that creates Assets from an Opportunity's line items (Opportunity Products). 

Static - Master Trigger call:
OpportunityTriggerHandler.createAssets(Trigger.new)
Question 1:

I saw this approach quite often in forums and blog articles - is this approach generally recommended and reasonable?

Non-Static - Master Trigger call:
OpportunityTriggerHandler oppHandler = new OpportunityTriggerHandler();
oppHandler.createAssets(Trigger.new);
Question 2

Can I consider non-static as best practice and if yes, why?

Looking forward to your feedback!
 
  • September 16, 2019
  • Like
  • 1