• golu
  • NEWBIE
  • 110 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 30
    Questions
  • 12
    Replies
Hi,
I am trying to pass the values from apex controller to visualforce page for radio buttons. Then i want to pass back the selected value in the controller. can anybody please help. The code written so far 
Visualforce page 



 <apex:repeat value="{!optionsListvf}" var="s">
                <apex:selectRadio >
                    <apex:selectOption > {!s} </apex:selectOption>
                </apex:selectRadio>
            </apex:repeat>




Apex class 

 public List<string> optionsListvf {get;set;}
    
    Public static String buttonbehaviourvf{get;set;}
    
    public  QuestionAnswerController(){
        String question =apexpages.currentpage().getparameters().get('question');
        String optionsList=apexpages.currentpage().getparameters().get('optionsList');
        String buttonbehaviour = apexpages.currentpage().getparameters().get('buttonbehaviour');
        questionvf=question;
        String finalOptions =  optionsList.replace('(','').replace(')','');
        optionsListvf=finalOptions.split(',');
        buttonbehaviourvf=buttonbehaviour;
        
    }

 
  • September 12, 2019
  • Like
  • 0
Hi All, 
I am able to create the get the values from json in my apex wrapper . But how do I iterate over it and store in task object. I want to store caller_number from the json in task records.Please help. Below is my code:
public class MyOperatorController {
    public static void Getlogs(){
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://developers.myoperator.co/search');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        request.setHeader('Accept','application/json');
        request.setBody('{"token" : "cc5ceab6c02ef8699a82f8178b5c1596"}');
        HttpResponse response = http.send(request);
   
        system.debug('response------'+response.getBody());
        System.debug('STATUS:'+response.getStatus());
        
      JSON2Apex jsonval= JSON2Apex.parse(response.getBody());  
    system.debug('--jsonval---'+jsonval);
    
}

My Json response sample is :
{
    "status": "success",
    "code": 200,
    "data": {
        "total": 71,
        "max_score": null,
        "hits": [
            {
                "_index": "latestlogs",
                "_type": "logs",
                "user_id": "79b4935e0bc4e689bf2fe60ba2fed8bc7b914e4e",
                "_score": 16.230835,
                "_source": {
                    "allcaller_id": "79b4935e0bc4e689bf2fe60ba2fed8bc7b914e4e",
                    "source": "2",
                    "company_id": "5d08992bd0309594",
                    "caller_number": "+916289030819",
                    "caller_number_raw": "6289030819",
                    "_cm": "",
                    "start_time": 1561034490,
                    "_ms": 1561034490000,
                    "seconds": 45690,
                    "end_time": 1561034492,
                    "synced_time": 1561034510,
                    "_drs": 2,
                    "duration": "00:00:02",
                    "_drm": 0.03,
                    "type": 1,
                    "event": 2,
                    "status": 1,
                    "fileurl": "",
                    "filename": "",
                    "comments": null,
                    "additional_parameters": [
                        {
                            "ky": "unique_id",
                            "vl": "5d0b7f0ed0eca615"
                        },
                        {
                            "ky": "is_starred",
                            "vl": "0"
                        },
                        {
                            "ky": "view_type",
                            "vl": "2"
                        },
                        {
                            "ky": "is_commented",
                            "vl": "0"
                        },
                        {
                            "ky": "is_archived",
                            "vl": "0"
                        }
                    ],
                    "country": "91",
                    "state": "IN",
                    "log_details": [
                        {
                            "text": "",
                            "type": 1,
                            "duration": "00:00:02",
                            "start_time": 1561034490,
                            "end_time": 1561034492,
                            "action": "received",
                            "received_by": [
                                {
                                    "user_id": "5d08992bd3b04894",
                                    "name": "Manras Technology",
                                    "email": "rohit.aryan@manras.in",
                                    "extension": "10",
                                    "contact_number_raw": "+919041910069",
                                    "contact_number": "9041910069"
                                }
                            ]
                        }
                    ],
                    "_us": [
                        {
                            "ky": "5d08992bd3b04894",
                            "vl": "received"
                        }
                    ],
                    "_tc": [
                        {
                            "ye": "5d08992bd3b04894",
                            "yf": 2
                        }
                    ]
                }
            },
            {
                "_index": "latestlogs",
                "_type": "logs",
                "user_id": "646a535ebd481cb362c71ca1e8922ad698639d01",
                "_score": 16.142824,
                "_source": {
                    "allcaller_id": "646a535ebd481cb362c71ca1e8922ad698639d01",
                    "source": "2",
                    "company_id": "5d08992bd0309594",
                    "caller_number": "+915227188769",
                    "caller_number_raw": "5227188769",
                    "_cm": "",
                    "start_time": 1561029280,
                    "_ms": 1561029280000,
                    "seconds": 40480,
                    "end_time": 1561029280,
                    "synced_time": 1561034507,
                    "_drs": 0,
                    "duration": "00:00:00",
                    "_drm": 0,
                    "type": 1,
                    "event": 1,
                    "status": 1,
                    "fileurl": "",
                    "filename": "",
                    "comments": null,
                    "additional_parameters": [
                        {
                            "ky": "unique_id",
                            "vl": "5d0b7f0be1da7596"
                        },
                        {
                            "ky": "is_starred",
                            "vl": "0"
                        },
                        {
                            "ky": "view_type",
                            "vl": "2"
                        },
                        {
                            "ky": "is_commented",
                            "vl": "0"
                        },
                        {
                            "ky": "is_archived",
                            "vl": "0"
                        }
                    ],
                    "country": "91",
                    "state": "UP, IN",
                    "log_details": [
                        {
                            "text": "",
                            "type": 1,
                            "duration": "00:00:00",
                            "start_time": 1561029280,
                            "end_time": 1561029280,
                            "action": "received",
                            "received_by": [
                                {
                                    "user_id": "5d08992bd3b04894",
                                    "name": "Manras Technology",
                                    "email": "rohit.aryan@manras.in",
                                    "extension": "10",
                                    "contact_number_raw": "+919041910069",
                                    "contact_number": "9041910069"
                                }
                            ]
                        }
                    ],
                    "_us": [
                        {
                            "ky": "5d08992bd3b04894",
                            "vl": "received"
                        }
                    ],
                    "_tc": [
                        {
                            "ye": "5d08992bd3b04894",
                            "yf": 0
                        }
                    ]
                }
            },
            {
                "_index": "latestlogs",
                "_type": "logs",
                "user_id": "6d3733ce3dcd084e1cf38e8a0f8c6efcbd2e975a",
                "_score": 16.142824,
                "_source": {
                    "allcaller_id": "6d3733ce3dcd084e1cf38e8a0f8c6efcbd2e975a",
                    "source": "2",
                    "company_id": "5d08992bd0309594",
                    "caller_number": "+915227188769",
                    "caller_number_raw": "5227188769",
                    "_cm": "",
                    "start_time": 1561028633,
                    "_ms": 1561028633000,
                    "seconds": 39833,
                    "end_time": 1561028633,
                    "synced_time": 1561034510,
                    "_drs": 0,
                    "duration": "00:00:00",
                    "_drm": 0,
                    "type": 1,
                    "event": 1,
                    "status": 1,
                    "fileurl": "",
                    "filename": "",
                    "comments": null,
                    "additional_parameters": [
                        {
                            "ky": "unique_id",
                            "vl": "5d0b7f0eb2a91576"
                        },
                        {
                            "ky": "is_starred",
                            "vl": "0"
                        },
                        {
                            "ky": "view_type",
                            "vl": "2"
                        },
                        {
                            "ky": "is_commented",
                            "vl": "0"
                        },
                        {
                            "ky": "is_archived",
                            "vl": "0"
                        }
                    ],
                    "country": "91",
                    "state": "UP, IN",
                    "log_details": [
                        {
                            "text": "",
                            "type": 1,
                            "duration": "00:00:00",
                            "start_time": 1561028633,
                            "end_time": 1561028633,
                            "action": "received",
                            "received_by": [
                                {
                                    "user_id": "5d08992bd3b04894",
                                    "name": "Manras Technology",
                                    "email": "rohit.aryan@manras.in",
                                    "extension": "10",
                                    "contact_number_raw": "+919041910069",
                                    "contact_number": "9041910069"
                                }
                            ]
                        }
                    ],
                    "_us": [
                        {
                            "ky": "5d08992bd3b04894",
                            "vl": "received"
                        }
                    ],
                    "_tc": [
                        {
                            "ye": "5d08992bd3b04894",
                            "yf": 0
                        }
                    ]
                }
            }

 
  • June 22, 2019
  • Like
  • 0
Hi ,
I want to transfer files from one object to another. Custom object A with record id ( 1,2,3,4) maps to custom object b with record id ( 5,6,7,8 ) respectively. I want to transfer the files of record 1 to record 5 , 2 to record 6, 3 to record 7 and so on. Can anyone please pass me the code snippet to do the same?
  • June 01, 2019
  • Like
  • 0
Hi,
I want to split the list into two lists and insert a custom object record if the original list size is greater than 5000. Can someone please provide the code snippet for it? In the below code if the size of activityids is greater than 5000, then one more history rec should be inserted storing the activity ids greater than 5000. 
 
//if(activityIds.size() > 5000) split the list into  different list to insesrt
        History__c historyrec = new History__c();
        historyrec.Message__c = message;
        historyrec.Schedule_Date_Time__c = scheduleDateTime;
        historyrec.Activity_Ids__c = String.valueOf(activityIds);
        historyrec.Status__c = status;
        insert historyrec;

 
  • May 06, 2019
  • Like
  • 0
In the below code , i am doing a callout in line 23 and 24. But in debug logs it throws error saying "i cannot do a callout from a trigger". I tried using future . But in future i cannot pass list of SObject. I am not able to pass the code in queueable context. Can anyone please help to make it work. 
public class CommunicatoHistoryHelper implements Queueable, Database.allowscallouts{
    public static void createUpdateActivity(List<Communicato_History__c> lstComHistory){
        SMS_Configuration__c smsConfig = SMS_Configuration__c.getOrgDefaults();
        List<id> activityids = new List<Id>();
        List<Task> updateLstTask = new List<Task>();
        List<Communicat_O_activity__c> updateComActivity = new List<Communicat_O_activity__c>();
        for (Communicato_History__c com : lstComHistory) {
            String s = com.communicat_o__Activity_Ids__c;
            if(s.contains('(') || s.contains(')')) {
                s=s.replace('(','').replace(')','');
            }
            system.debug('s' + s);
            if (com.Status__c == CommunicatoUtilityClass.ACTIVITY_STATUS_COMPLETED){ 
                activityids.add(s);
                system.debug('activityids14' + activityids);
            }
        }
        List<API_Configuration__mdt> apiConfig;
        apiConfig = [SELECT Class_Name__c FROM API_Configuration__mdt LIMIT 1];
        try{
            if(activityids.size() > 0 && activityids.size() == 1){
                Type t = Type.forName(apiConfig[0].class_name__c);
                MessageService message = (MessageService)t.newInstance();
                message.sendSingleMessage('xxxxxxxxxx','testsms');
            }
        }
        catch(Exception e){
            system.debug('Class name is not set in api configuration metadata record');  
        }
        try{
            if(activityids.size() > 1){
                Type t = Type.forName(apiConfig[0].class_name__c);
                MessageService message = (MessageService)t.newInstance();
                message.sendBulkMessage();    
            }
        }
        catch(Exception e){
            system.debug('Class name is not set in api configuration metadata record');
        }
        
        List<SObject> sObj = new List<SObject>();
        String strQuery;
        List<Task> lstTask = new List<Task>();
        List<Communicat_O_activity__c> comActivity = new List<Communicat_O_activity__c>();
        if(smsConfig.Use_Salesforce_Activity__c){
            strQuery = 'Select Status FROM Task WHERE Id IN ';strQuery += ':activityids';
        }
        else{
            strQuery = 'Select Status__c FROM Communicat_O_activity__c WHERE Id IN ';strQuery += ':activityids';
            
        }
        sObj = Database.query(strQuery);
        for(sObject s : sObj){
            if(smsConfig.Use_Salesforce_Activity__c){
                Task t = (Task)s;
                t.status = CommunicatoUtilityClass.ACTIVITY_STATUS_COMPLETED;
                lstTask.add(t);
            }   
            
            else{
                Communicat_O_activity__c com = (Communicat_O_activity__c)s;
                com.status__c = CommunicatoUtilityClass.ACTIVITY_STATUS_COMPLETED;
                comActivity.add(com);
            }
        }
        if(lstTask.size()>0){
            update lstTask;
        }
        if(comActivity.size()>0){
            update comActivity;
        }
    }
    public void execute(QueueableContext context) {
       // this.createUpdateActivity();
    }
}

 
  • April 30, 2019
  • Like
  • 0
How do i call my interface from apex static methods.

I have a interface with below code:
global interface xyz{
    String a();
    String b();
}

Hi want to call a() and b() in another apex class .
public static void createUpdateActivity(List<Communicato_History__c> lstComHistory){
        List<id> activityids = new List<Id>();
        
        if(activityids.size() > 0 && activityids.size() == 1 ){
            // xyz.a();
         
        }

How to do it? It throws error saying non-static methods cannot be referred from static context.
 
  • April 25, 2019
  • Like
  • 0
Hi,
I am trying to run the below code but line 20 is giving me null. Can anyone please help me. I am able to reurn the list of activity ids but i am not able to pass the value in method in line 19
public class SMSHelper {
    public static void createActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime){
        List<id> activityIds ;
        SMS_Configuration__c smsConfig = SMS_Configuration__c.getOrgDefaults();
        String status = scheduleDateTime == null?'Completed':'Scheduled';
        if(smsConfig.Use_Salesforce_Activity__c){
            createSalesforceActivities(recordIdSet, message, scheduleDateTime, status);
        }
        else{
            createCommunicatoActivities(recordIdSet, message, scheduleDateTime, status);
        }
        SMSHelper.createCommunicatOHistory(activityIds,message,scheduleDateTime);
        
        if(status == 'Completed'){
            
        } 
    }
    
    public static void createCommunicatOHistory(List<Id> activityIds, String message , Datetime scheduleDateTime){
        system.debug('activityIds' + activityIds);
        Communicato_History__c historyrec = new Communicato_History__c();
        historyrec.Message__c = message;
        historyrec.Schedule_Date_Time__c = scheduleDateTime;
        historyrec.communicat_o__Activity_Ids__c = String.valueOf(activityIds);
        // historyrec.Status__c = status;
        insert historyrec;
        system.debug('historyrec' + historyrec);
    }
    
    public static List<Id> createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        return activityIds;
        
    }
    
    public static List<id> createCommunicatoActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Communicat_O_activity__c> lstComActivity = new List<Communicat_O_activity__c>();
        for(String id: recordIdSet){
            Communicat_O_activity__c comObj = new Communicat_O_activity__c();
            
            comObj.Schedule_Date_Time__c = scheduleDateTime;
            comObj.Status__c = status;
            comObj.Message__c = message;
            comObj.Related_To__c = id;
            lstComActivity.add(comObj); 
        }
        
        insert lstComActivity;
        List <id> activityIds = new List<Id>();
        if(lstComActivity.size()>0){
            for(Communicat_O_activity__c com : lstComActivity){
                activityIds.add(com.id);
            }
        }
        return activityIds;
    }
}

 
  • April 23, 2019
  • Like
  • 0
public static void createCommunicatOHistory(List<Id> activityIds, ){
       
        
    }
    
    public static List<Id> createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        return activityIds;
    }

Hi,
I want to pass the activityIds returned as a parameter to createCommunicatOHistory method. How can i do it?
  • April 23, 2019
  • Like
  • 0
Hi,
Can someone please help me resolve the issue. I am getting null pointer at line 21 .         SMSHelper.createCommunicatOHistory(activityIds, message, scheduleDateTime);
public class SMSHelper {
    public static List<Task> lstTask;
    public static List<Communicat_O_activity__c> lstComActivity;
    public SMSHelper(){
        lstTask = new List<Task>();
        lstComActivity = new List<Communicat_O_activity__c>();
    } 
    
    
    public static void createActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime){
        SMS_Configuration__c smsConfig = SMS_Configuration__c.getOrgDefaults();
        String status = scheduleDateTime == null?'Completed':'Scheduled';
        List<Id> activityIds = new List<Id>();
        if(smsConfig.Use_Salesforce_Activity__c){
            
            createSalesforceActivities(recordIdSet, message, scheduleDateTime, status);
        }
        else{
            createCommunicatoActivities(recordIdSet, message, scheduleDateTime, status);
        }
        SMSHelper.createCommunicatOHistory(activityIds, message, scheduleDateTime);
        
        if(status == 'Completed'){
            
        } 
        // SMSHelper.createCommunicatOHistory(List<id> activityIds);
    }
    
    public static void createCommunicatOHistory(List<id> activityIds, String message, Datetime scheduleDateTime){
        system.debug('lsttask' + lstTask);
        system.debug('comactivity' + lstComActivity);
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        if(lstComActivity.size()>0){
            for(Communicat_O_activity__c com : lstComActivity){
                activityIds.add(com.id);
            }
        }
        Communicato_History__c comHistory = new Communicato_History__c();
        comHistory.Message__c = message;
        comHistory.Schedule_Date_Time__c = scheduleDateTime;
        comHistory.Activity_Ids__c = String.valueOf(activityIds);
        insert comHistory;
    }
    
    public static void createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        
        
        // Map<Id, Task> TaskMap = tnew Map<Id, Task>(lstTask);
    }
    
    public static void createCommunicatoActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Communicat_O_activity__c> lstComActivity = new List<Communicat_O_activity__c>();
        
        for(String id: recordIdSet){
            Communicat_O_activity__c comObj = new Communicat_O_activity__c();
            
            comObj.Schedule_Date_Time__c = scheduleDateTime;
            comObj.Status__c = status;
            comObj.Message__c = message;
            comObj.Related_To__c = id;
            
            lstComActivity.add(comObj); 
        }
        
        insert lstComActivity;
        
    }
    
}

 
  • April 22, 2019
  • Like
  • 0
How do i pass the value of list from a static void method to another method.
 
public static void abcd(List<Id> activityIds, String message, Datetime scheduleDateTime){
            
        }





public static void createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
            List<Task> lstTask = new List<Task>();
            
            for(String id: recordIdSet){
                Task taskObj = new Task();
                taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
                taskObj.Status = status;
                taskObj.Description = message;
                taskObj.WhoId = id;
                
                lstTask.add(taskObj); 
            }
            insert lstTask;
        }

So basically i want to pass the list of inserted task record values to static void abcd method. 
what is the best possible way?
  • April 22, 2019
  • Like
  • 0
Hi ,

I have written the below trigger code. It is working fine but is not at all optimised. It is having three for loops. Can anyone please guide me with a code snippet.
trigger AttachmentTrigger on Attachment (after insert) {
    List<Account> accountList = new List<Account>();
    List<Lead> leadlist = new List<Lead>();
    List<String> emails = new List<String>();
    Set<Id> accIds = new Set<Id>();
    List<Attachment> atts = new List<Attachment>();
    for(Attachment att : trigger.New){
        if(att.ParentId.getSobjectType() == Lead.SobjectType){
            accIds.add(att.ParentId);
        }
        
        leadList = [Select id , email from lead where id in : accIds];
        for(Lead l : leadlist){
            emails.add(l.email);
        }
        accountList = [select id, Email__c from Account where email__c in : emails];
        if(accountList!=null && accountList.size()>0){
            for(Account acc : accountList){
                for(Lead ld : leadlist){
                    if(ld.email == acc.email__c){
                        Attachment newFile = new attachment();
                        newfile.Body = att.Body;
                        newfile.Name = att.Name;
                        newfile.Description = att.Description;
                        newfile.ParentId = acc.id;
                        atts.add(newFile);  
                    }
                }
            }
        }
    }
    if(!atts.isEmpty()){
        insert atts;
    }
}

 
  • April 14, 2019
  • Like
  • 0
Hi,

i am cponverting my lead to person account using the below code. I want to clone the attachment in lead to person account as well. How do i do it?
trigger LeadCreateAccount on Lead (Before Insert) {
    Public List<Account> lstAccts = new List<Account>();
    Public List<Account> lstNewAccts = new List<Account>();
    Public set<String> setLeadNames = new set<String>();
    public String name = '';
    Id personAccountRecordTypeId =  Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId();
   
 for(Lead l: trigger.new)
    {
        
        Account acct = new account();
        acct.FirstName = l.firstname;
        acct.LastName = l.lastname;
        acct.Email__c = l.Email;
        acct.RecordTypeId = personAccountRecordTypeId;
        lstNewAccts.add(acct);
        
    }
    
    if (lstNewAccts.size() > 0)
        insert lstNewAccts;

}

 
  • April 11, 2019
  • Like
  • 0
How do i make a post callout for this specific url ?

http://www.test.com/ComposeSMS.aspx?username=username&password=password&sender=senderid&to=MobileNo&message=Message

I am not able to figure out how to create the header and body for this specific url. I need to passs username , password , senderid , mobile number and message as parameters.

Any code snippet will be highly appreciated
  • April 07, 2019
  • Like
  • 0
Hi,
Can anyone please help me in resolving the error? I am getting the error attempt the dereference a null object when i do a callout.
Issue is with listComActivity
Below is the code:
public class SendSMSFromTwilio implements Database.AllowsCallouts , Queueable{
    
    public String phNumber;
    public String smsBody;
    String accountSid;
    string token;
    String fromPhNumber;
    errorResponseWrapper erw;
    public List<communicat_o__Communicat_O_activity__c> listComActivity;
    List<communicat_o__API_Credentials__mdt> apiCredentials;
    public SendSMSFromTwilio(List<communicat_o__Communicat_O_activity__c> listOfComActivity){
        List<communicat_o__Communicat_O_activity__c> listComActivity = new List<communicat_o__Communicat_O_activity__c>();
        listComActivity.addAll(listOfComActivity);
        system.debug('sadasdasdasd' + listComActivity);
        apiCredentials = [Select id,
                          communicat_o__AccountSid__c,
                          communicat_o__EndPoint__c,
                          communicat_o__FromPhNumber__c,
                          communicat_o__Token__c,
                          communicat_o__Version__c
                          FROM communicat_o__API_Credentials__mdt
                          WHERE developername = 'Twilio'
                          LIMIT 1];
        accountSid = apiCredentials[0].communicat_o__AccountSid__c;
        token = apiCredentials[0].communicat_o__Token__c;
        fromPhNumber = apiCredentials[0].communicat_o__FromPhNumber__c;
    }
    
    public void processSms(){
        if (!(listComActivity.IsEmpty()))
            for (communicat_o__Communicat_O_activity__c comActivity : listComActivity){
                HttpRequest req = new HttpRequest();
                req.setEndpoint(apiCredentials[0].communicat_o__EndPoint__c + accountSid+'/SMS/Messages.json');
                req.setMethod('POST');
                String VERSION  = apiCredentials[0].communicat_o__Version__c;
                req.setHeader('X-Twilio-Client', 'salesforce-' + VERSION);
                req.setHeader('User-Agent', 'twilio-salesforce/' + VERSION);
                req.setHeader('Accept', 'application/json');
                req.setHeader('Accept-Charset', 'utf-8');
                req.setHeader('Authorization','Basic '+EncodingUtil.base64Encode(Blob.valueOf(accountSid+':' +token)));
                req.setBody('To='+EncodingUtil.urlEncode(phNumber,'UTF-8')+'&From='+EncodingUtil.urlEncode('+' + String.valueOf(comActivity.communicat_o__Phone_Number__c),'UTF-8')+'&Body='+comActivity.communicat_o__Message__c);
                Http http = new Http();
                HTTPResponse res = http.send(req);
                System.debug(res.getBody());
                if(res.getStatusCode()==201)
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'SMS Sent Successfully'));
                    system.debug('SMS Sent Successfully');
                
                else{
                    
                    erw =(errorResponseWrapper)json.deserialize(res.getBody(),errorResponseWrapper.class);
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,erw.message));
                    system.debug('erw' + erw.message);
                }
                
            }
    }
    public void execute(QueueableContext ctx) {
        this.processSms();
    }
    
    public class errorResponseWrapper{
        
        String code;
        String message;
        String moreInfo;
        String status;    
        
    }
    
    
}

 
  • April 06, 2019
  • Like
  • 0
Hi ,
I am able to get the values of the first column using the code below. How can i get the values of second column? Mine is a tabular report
Set<Id> theIDs = new Set<Id>();
List<String> s = new List<String>();
List <Report> reportList = [SELECT Id from report where id = '00OO0000000uUL3' ];
system.debug('reportList' + reportList);
String reportId = (String)reportList.get(0).get('Id');
system.debug('reportId1');
Reports.reportResults results = Reports.ReportManager.runReport(reportID, true);
Reports.ReportFactWithDetails detailFact =(Reports.ReportFactWithDetails) results.getFactMap().get('T!T');
List<Reports.ReportDetailRow> allRows = detailFact.getRows();
system.debug('allRows' + allRows );
for (Integer r = 0; r < allRows.size(); r++) { 
    theIDs.add((Id) allRows.get(r).getDataCells().get(0).getValue());
}
for (Integer r = 0; r < allRows.size(); r++) { 
    s.add((Id) allRows.get(r).getDataCells().get(0).getValue());
}

system.debug('theIDs' + theIDs);
system.debug('detailFact'+ detailFact);

 
  • March 28, 2019
  • Like
  • 0
Hi, 
I am trying to pass the value from one component to another with attributes but it is not working . Can anyone please help?
I want to send the value from lightningLookupComponent to sendSMS_report component. I want to pass the value of "selItem" to sendSMS_report controller.
Below is the code for lightningLookupComponent:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction">
    <aura:attribute Name="selItem" type="object"  access="public" /> 
    <aura:attribute Name="selItem1" type="object"  access="public" />
    <aura:attribute Name="selItem2" type="object"  access="public" />
    <aura:attribute Name="selItem3" type="object"  access="public" />
    <div class="slds">
        <div class="slds-grid slds-wrap">
            <div class="slds-size_1-of-1 
                        slds-small-size_1-of-1 
                        slds-medium-size_1-of-2 
                        slds-large-size_1-of-4 ">
                <c:lightningLookup objectName="Report"
                          field_API_text="Name"
                          field_API_val="Id"
                          limit="4"
                          field_API_search="Name"
                          lookupIcon="standard:report" 
                          selItem="{!v.selItem}" 
                          placeholder="Enter space after text to search report"
                          />  
                
                <aura:if isTrue="{! not(empty(v.selItem)) }"> 
                    <br />
                    This is Parent Lightning component <br />
                    Item Selected : <br />
                    ID - {#v.selItem.val} <br /> 
                    Text - {#v.selItem.text}<br />
                    Object - {#v.selItem.objName}<br />
                    <c:sendSMS_Report/>
                </aura:if> 
            </div>
            
    </div>
    </div>
</aura:component>

Code for sendSMS_report controller. I want to pass the values in one of the setPrams function.
({
   sendNowOrLater : function(component, event, helper, caller){
       $A.util.toggleClass(component.find("mySpinner"),"slds-show");
       var action;
       if(caller == 'sendReportSMSNow'){
           action = component.get("c.sendSMS_Report");
           action.setParams({ 
           message          :   component.get("v.selectedTemplateBody"),
           recordId         :   component.get("v.recordId")
           
       });
       }else{
           action = component.get("c.sendSMS_Report");
           action.setParams({ 
           scheduleDateTime :   component.get("v.scheduleDateTime"),
           message          :   component.get("v.selectedTemplateBody"),
           recordId         :   component.get("v.recordId")
           
       });
       }
       console.log(action);
       
       action.setCallback(this, function(response) {
           var state = response.getState();
           if (state === "SUCCESS") {
               
               $A.util.toggleClass(component.find("mySpinner"),"slds-hide");
               var toastEvent = $A.get("e.force:showToast"); //
               /**/
               toastEvent.setParams({
                   title: "Success!",
                   message: "The record has been created successfully ."
                   
               });
               toastEvent.fire();
               var modal = component.find("Modal");
               $A.util.addClass(modal, 'hideDiv');
               var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
               dismissActionPanel.fire(); 
               
               
           }else if (state === "ERROR") {
               var errors = response.getError();
               if (errors) {
                   if (errors[0] && errors[0].message) {
                       var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                       dismissActionPanel.fire(); 
                       var toastEvent = $A.get("e.force:showToast"); // //
                       toastEvent.setParams({
                           title: "Failed",
                           message: "The record was not saved"
                           
                       });
                       toastEvent.fire();
                   }
               } 
           }     
       });
       $A.enqueueAction(action);
   }
})



 
  • March 21, 2019
  • Like
  • 0
Hi,

I want to open my lightning component which is inside a visualforce page as a modal. How can i do it?
reason : i want o display my lightning component in the list view quick action button but it is not possible. So i used vf page to display the component. But my requirement is opening this visualforce page as a model.

Code for the visualforce page:
<apex:page sidebar="false" standardController="Contact"  recordSetVar="selectedObjects" extensions="test" showHeader="false"  standardStylesheets="True" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" cache="false" expires="0">
   <apex:includeLightning />
    
   <div id="lightning" />
    
   <script>
        $Lightning.use("c:TestComponent", function() {
            $Lightning.createComponent(
                "TestComponent",
                {recordId : "{!selected}",
                 objName  : "{!objName}"},
                "lightning",
                function(cmp) {
                    
                });
            });
   </script>
    
</apex:page>

 
  • March 18, 2019
  • Like
  • 0
Can anyone please help me with making the javascript code reusable?
There is almost same piece of code in both the functions.
Please provide the snippet
({
    sendLater : function(component, event, helper) { 
        var recId = component.get("v.recordId");
        console.log(recId);
        var smsBody = component.get("v.selectedTemplateBody");
        console.log(smsBody);
        var scheduleDateTime = component.get("v.scheduleDateTime");
        console.log(scheduleDateTime);
        $A.util.toggleClass(component.find("mySpinner"),"slds-show");
        var action = component.get("c.sendLaterButton");
        console.log(action);
        action.setParams({ 
            scheduleDateTime :   component.get("v.scheduleDateTime"),
            message          :   smsBody,
            recordId         :   component.get("v.recordId"),
            objName          :   component.get("v.sObjectName")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                
                $A.util.toggleClass(component.find("mySpinner"),"slds-hide");
                var toastEvent = $A.get("e.force:showToast"); //
                /**/
                toastEvent.setParams({
                    title: "Success!",
                    message: "The record has been created successfully ."
                    
                });
                toastEvent.fire();
                var modal = component.find("Modal");
                $A.util.addClass(modal, 'hideDiv');
                var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                dismissActionPanel.fire(); 
                
                
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                        dismissActionPanel.fire(); 
                        var toastEvent = $A.get("e.force:showToast"); // //
                        toastEvent.setParams({
                            title: "Failed",
                            message: "The record was not saved"
                            
                        });
                        toastEvent.fire();
                    }
                } 
            }     
        });
        $A.enqueueAction(action);
    },
    
    sendNow : function(component, event, helper) { 
        var recId = component.get("v.recordId");
        console.log(recId);
        var smsBody = component.get("v.selectedTemplateBody");
        console.log(smsBody);
        var scheduleDateTime = component.get("v.scheduleDateTime");
        console.log(scheduleDateTime);
        $A.util.toggleClass(component.find("mySpinner"),"slds-show");
        var action = component.get("c.sendNowButton");
        console.log(action);
        action.setParams({ 
            scheduleDateTime :   component.get("v.scheduleDateTime"),
            message          :   smsBody,
            recordId         :   component.get("v.recordId"),
            objName          :   component.get("v.sObjectName")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                
                $A.util.toggleClass(component.find("mySpinner"),"slds-hide");
                var toastEvent = $A.get("e.force:showToast"); //
                /**/
                toastEvent.setParams({
                    title: "Success!",
                    message: "The record has been created successfully ."
                    
                });
                toastEvent.fire();
                var modal = component.find("Modal");
                $A.util.addClass(modal, 'hideDiv');
                var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                dismissActionPanel.fire(); 
                
                
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                        dismissActionPanel.fire(); 
                        var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title: "Failed",
                            message: "The record was not saved."
                            
                        });
                        toastEvent.fire();
                    }
                } 
            }     
        });
        $A.enqueueAction(action);
    }
})

 
  • March 14, 2019
  • Like
  • 0
Hi,

I am retrieving the email templates and showing in my lightning component. Currently the email template body in the component is displaying {!Contact.FirstName}. I want to replace it with recordId.name. Can anyone please help me with that?

Code for javascript controller
({
	doinit: function (component, event, helper) {
        
		var smsTemplatesAction = component.get("c.getSMSTemplates");

		smsTemplatesAction.setCallback(this, function (response) {
			var state = response.getState();
			var templates = response.getReturnValue();
			if (state === "SUCCESS") {
				var templateList = [];
				templateList.push({ "class": "optionClass", label: 'Select Value', value: '' });
				for (var key in response.getReturnValue()) {
					templateList.push({ "class": "optionClass", label: templates[key].Name, value: key });
				}
				component.find("selectTemplate").set("v.options", templateList);
			}
		});

		$A.enqueueAction(smsTemplatesAction);

		var charLimitAction = component.get("c.getCharacterLimit");
		charLimitAction.setCallback(this, function (response) {
			var state = response.getState();
			if (state === "SUCCESS") {
				component.set("v.charLimit", response.getReturnValue());
				component.set("v.charsRemaining", response.getReturnValue());
			}
		});
		$A.enqueueAction(charLimitAction);

	},
	fetchbody: function (component, event, helper) {
		var templateId = component.find('selectTemplate').get('v.value');
		var templateBody;
        var recordId = component.get("v.recordId.name");
		if (templateId == '') {
			templateBody = '';
		}
		else {
			var smsTemplatesAction = component.get("c.getSMSTemplateById");

			smsTemplatesAction.setParams({
				"templateId": templateId
			})

			smsTemplatesAction.setCallback(this, function (response) {
				var state = response.getState();
                
				if (state === "SUCCESS") {
                    
					templateBody = response.getReturnValue();
                    console.log(templateBody);
                    component.set("v.selectedTemplateBody", templateBody);

					var charLimit = component.get("v.charLimit");
					var textarealength = templateBody.length;
					if (textarealength != '' || textarealength != null) {
						var totalmax = charLimit - textarealength;
						component.set('v.charsRemaining', totalmax);
					}
				}
			});

			$A.enqueueAction(smsTemplatesAction);
		}
	},
})

Please check the fetchBody function.
  • March 13, 2019
  • Like
  • 0
Hi ,
I have the below code
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:attribute name="scheduleDateTime" type="DateTime" />
    <aura:attribute name="selectedTemplateBody" type="String" />
    <article class="slds-card">
        <div class="slds-card__header slds-grid">
            <header class="slds-media slds-media_center slds-has-flexi-truncate">
                <div class="slds-media__figure">
                    <span class="slds-icon_container slds-icon-standard-account" title="SMS">
                        <span class="slds-icon_container" title="SMS">
                            <lightning:icon iconName="standard:sms" size="small" alternativeText="Indicates SMS" />
                            <span class="slds-assistive-text">SMS</span>
                        </span>
                        <span class="slds-assistive-text">SMS</span>
                    </span>
                </div>
                <div class="slds-media__body">
                    <h2 class="slds-card__header-title">
                        <a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="SMS">
                            <span>SMS</span>
                        </a>
                    </h2>
                </div>
            </header>
        </div>
        <div class="slds-card__body slds-card__body_inner">
            <c:messageBody fromNumber="{!v.fromNumber}" selectedTemplateBody="{!v.selectedTemplateBody}" scheduleDateTime="{!v.scheduleDateTime}"
                           aura:id="sendMessageBodyId" />
        </div >
        <div class="slds-align_absolute-center">
          	<lightning:button variant="brand" label="Send Now" title="Send Now" onclick="{! c.buttonAction}"/>
            <lightning:button variant="brand" label="Send Later" title="Send Later" onclick="{! c.handleClick }"/>
            <lightning:button variant="brand" label="Cancel" title="Cancel" onclick="{! c.handleClick }"/>
              
        </div>
        <footer class="slds-card__footer">
            <a class="slds-card__footer-action" href="javascript:void(0);">View All
                <span class="slds-assistive-text">Contacts</span>
            </a>
        </footer>
    </article>
</aura:component>

I want send now button to be visible only when v.scheduleDateTime is populated. Can anyone please help?
  • March 11, 2019
  • Like
  • 0
In the below code , i am doing a callout in line 23 and 24. But in debug logs it throws error saying "i cannot do a callout from a trigger". I tried using future . But in future i cannot pass list of SObject. I am not able to pass the code in queueable context. Can anyone please help to make it work. 
public class CommunicatoHistoryHelper implements Queueable, Database.allowscallouts{
    public static void createUpdateActivity(List<Communicato_History__c> lstComHistory){
        SMS_Configuration__c smsConfig = SMS_Configuration__c.getOrgDefaults();
        List<id> activityids = new List<Id>();
        List<Task> updateLstTask = new List<Task>();
        List<Communicat_O_activity__c> updateComActivity = new List<Communicat_O_activity__c>();
        for (Communicato_History__c com : lstComHistory) {
            String s = com.communicat_o__Activity_Ids__c;
            if(s.contains('(') || s.contains(')')) {
                s=s.replace('(','').replace(')','');
            }
            system.debug('s' + s);
            if (com.Status__c == CommunicatoUtilityClass.ACTIVITY_STATUS_COMPLETED){ 
                activityids.add(s);
                system.debug('activityids14' + activityids);
            }
        }
        List<API_Configuration__mdt> apiConfig;
        apiConfig = [SELECT Class_Name__c FROM API_Configuration__mdt LIMIT 1];
        try{
            if(activityids.size() > 0 && activityids.size() == 1){
                Type t = Type.forName(apiConfig[0].class_name__c);
                MessageService message = (MessageService)t.newInstance();
                message.sendSingleMessage('xxxxxxxxxx','testsms');
            }
        }
        catch(Exception e){
            system.debug('Class name is not set in api configuration metadata record');  
        }
        try{
            if(activityids.size() > 1){
                Type t = Type.forName(apiConfig[0].class_name__c);
                MessageService message = (MessageService)t.newInstance();
                message.sendBulkMessage();    
            }
        }
        catch(Exception e){
            system.debug('Class name is not set in api configuration metadata record');
        }
        
        List<SObject> sObj = new List<SObject>();
        String strQuery;
        List<Task> lstTask = new List<Task>();
        List<Communicat_O_activity__c> comActivity = new List<Communicat_O_activity__c>();
        if(smsConfig.Use_Salesforce_Activity__c){
            strQuery = 'Select Status FROM Task WHERE Id IN ';strQuery += ':activityids';
        }
        else{
            strQuery = 'Select Status__c FROM Communicat_O_activity__c WHERE Id IN ';strQuery += ':activityids';
            
        }
        sObj = Database.query(strQuery);
        for(sObject s : sObj){
            if(smsConfig.Use_Salesforce_Activity__c){
                Task t = (Task)s;
                t.status = CommunicatoUtilityClass.ACTIVITY_STATUS_COMPLETED;
                lstTask.add(t);
            }   
            
            else{
                Communicat_O_activity__c com = (Communicat_O_activity__c)s;
                com.status__c = CommunicatoUtilityClass.ACTIVITY_STATUS_COMPLETED;
                comActivity.add(com);
            }
        }
        if(lstTask.size()>0){
            update lstTask;
        }
        if(comActivity.size()>0){
            update comActivity;
        }
    }
    public void execute(QueueableContext context) {
       // this.createUpdateActivity();
    }
}

 
  • April 30, 2019
  • Like
  • 0
Hi,
I am trying to run the below code but line 20 is giving me null. Can anyone please help me. I am able to reurn the list of activity ids but i am not able to pass the value in method in line 19
public class SMSHelper {
    public static void createActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime){
        List<id> activityIds ;
        SMS_Configuration__c smsConfig = SMS_Configuration__c.getOrgDefaults();
        String status = scheduleDateTime == null?'Completed':'Scheduled';
        if(smsConfig.Use_Salesforce_Activity__c){
            createSalesforceActivities(recordIdSet, message, scheduleDateTime, status);
        }
        else{
            createCommunicatoActivities(recordIdSet, message, scheduleDateTime, status);
        }
        SMSHelper.createCommunicatOHistory(activityIds,message,scheduleDateTime);
        
        if(status == 'Completed'){
            
        } 
    }
    
    public static void createCommunicatOHistory(List<Id> activityIds, String message , Datetime scheduleDateTime){
        system.debug('activityIds' + activityIds);
        Communicato_History__c historyrec = new Communicato_History__c();
        historyrec.Message__c = message;
        historyrec.Schedule_Date_Time__c = scheduleDateTime;
        historyrec.communicat_o__Activity_Ids__c = String.valueOf(activityIds);
        // historyrec.Status__c = status;
        insert historyrec;
        system.debug('historyrec' + historyrec);
    }
    
    public static List<Id> createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        return activityIds;
        
    }
    
    public static List<id> createCommunicatoActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Communicat_O_activity__c> lstComActivity = new List<Communicat_O_activity__c>();
        for(String id: recordIdSet){
            Communicat_O_activity__c comObj = new Communicat_O_activity__c();
            
            comObj.Schedule_Date_Time__c = scheduleDateTime;
            comObj.Status__c = status;
            comObj.Message__c = message;
            comObj.Related_To__c = id;
            lstComActivity.add(comObj); 
        }
        
        insert lstComActivity;
        List <id> activityIds = new List<Id>();
        if(lstComActivity.size()>0){
            for(Communicat_O_activity__c com : lstComActivity){
                activityIds.add(com.id);
            }
        }
        return activityIds;
    }
}

 
  • April 23, 2019
  • Like
  • 0
public static void createCommunicatOHistory(List<Id> activityIds, ){
       
        
    }
    
    public static List<Id> createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        List <id> activityIds = new List<Id>();
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        return activityIds;
    }

Hi,
I want to pass the activityIds returned as a parameter to createCommunicatOHistory method. How can i do it?
  • April 23, 2019
  • Like
  • 0
Hi,
Can someone please help me resolve the issue. I am getting null pointer at line 21 .         SMSHelper.createCommunicatOHistory(activityIds, message, scheduleDateTime);
public class SMSHelper {
    public static List<Task> lstTask;
    public static List<Communicat_O_activity__c> lstComActivity;
    public SMSHelper(){
        lstTask = new List<Task>();
        lstComActivity = new List<Communicat_O_activity__c>();
    } 
    
    
    public static void createActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime){
        SMS_Configuration__c smsConfig = SMS_Configuration__c.getOrgDefaults();
        String status = scheduleDateTime == null?'Completed':'Scheduled';
        List<Id> activityIds = new List<Id>();
        if(smsConfig.Use_Salesforce_Activity__c){
            
            createSalesforceActivities(recordIdSet, message, scheduleDateTime, status);
        }
        else{
            createCommunicatoActivities(recordIdSet, message, scheduleDateTime, status);
        }
        SMSHelper.createCommunicatOHistory(activityIds, message, scheduleDateTime);
        
        if(status == 'Completed'){
            
        } 
        // SMSHelper.createCommunicatOHistory(List<id> activityIds);
    }
    
    public static void createCommunicatOHistory(List<id> activityIds, String message, Datetime scheduleDateTime){
        system.debug('lsttask' + lstTask);
        system.debug('comactivity' + lstComActivity);
        if(lstTask.size()>0){
            for(Task t : lstTask){
                activityIds.add(t.id);
            }
        }
        if(lstComActivity.size()>0){
            for(Communicat_O_activity__c com : lstComActivity){
                activityIds.add(com.id);
            }
        }
        Communicato_History__c comHistory = new Communicato_History__c();
        comHistory.Message__c = message;
        comHistory.Schedule_Date_Time__c = scheduleDateTime;
        comHistory.Activity_Ids__c = String.valueOf(activityIds);
        insert comHistory;
    }
    
    public static void createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Task> lstTask = new List<Task>();
        
        for(String id: recordIdSet){
            Task taskObj = new Task();
            taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
            taskObj.Status = status;
            taskObj.Description = message;
            taskObj.WhoId = id;
            
            lstTask.add(taskObj); 
        }
        insert lstTask;
        
        
        // Map<Id, Task> TaskMap = tnew Map<Id, Task>(lstTask);
    }
    
    public static void createCommunicatoActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
        List<Communicat_O_activity__c> lstComActivity = new List<Communicat_O_activity__c>();
        
        for(String id: recordIdSet){
            Communicat_O_activity__c comObj = new Communicat_O_activity__c();
            
            comObj.Schedule_Date_Time__c = scheduleDateTime;
            comObj.Status__c = status;
            comObj.Message__c = message;
            comObj.Related_To__c = id;
            
            lstComActivity.add(comObj); 
        }
        
        insert lstComActivity;
        
    }
    
}

 
  • April 22, 2019
  • Like
  • 0
How do i pass the value of list from a static void method to another method.
 
public static void abcd(List<Id> activityIds, String message, Datetime scheduleDateTime){
            
        }





public static void createSalesforceActivities(List<Id> recordIdSet ,String message, Datetime scheduleDateTime, String status){
            List<Task> lstTask = new List<Task>();
            
            for(String id: recordIdSet){
                Task taskObj = new Task();
                taskObj.ActivityDate = Date.valueOf(scheduleDateTime);
                taskObj.Status = status;
                taskObj.Description = message;
                taskObj.WhoId = id;
                
                lstTask.add(taskObj); 
            }
            insert lstTask;
        }

So basically i want to pass the list of inserted task record values to static void abcd method. 
what is the best possible way?
  • April 22, 2019
  • Like
  • 0
Hi,

i am cponverting my lead to person account using the below code. I want to clone the attachment in lead to person account as well. How do i do it?
trigger LeadCreateAccount on Lead (Before Insert) {
    Public List<Account> lstAccts = new List<Account>();
    Public List<Account> lstNewAccts = new List<Account>();
    Public set<String> setLeadNames = new set<String>();
    public String name = '';
    Id personAccountRecordTypeId =  Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId();
   
 for(Lead l: trigger.new)
    {
        
        Account acct = new account();
        acct.FirstName = l.firstname;
        acct.LastName = l.lastname;
        acct.Email__c = l.Email;
        acct.RecordTypeId = personAccountRecordTypeId;
        lstNewAccts.add(acct);
        
    }
    
    if (lstNewAccts.size() > 0)
        insert lstNewAccts;

}

 
  • April 11, 2019
  • Like
  • 0
Hi,
Can anyone please help me in resolving the error? I am getting the error attempt the dereference a null object when i do a callout.
Issue is with listComActivity
Below is the code:
public class SendSMSFromTwilio implements Database.AllowsCallouts , Queueable{
    
    public String phNumber;
    public String smsBody;
    String accountSid;
    string token;
    String fromPhNumber;
    errorResponseWrapper erw;
    public List<communicat_o__Communicat_O_activity__c> listComActivity;
    List<communicat_o__API_Credentials__mdt> apiCredentials;
    public SendSMSFromTwilio(List<communicat_o__Communicat_O_activity__c> listOfComActivity){
        List<communicat_o__Communicat_O_activity__c> listComActivity = new List<communicat_o__Communicat_O_activity__c>();
        listComActivity.addAll(listOfComActivity);
        system.debug('sadasdasdasd' + listComActivity);
        apiCredentials = [Select id,
                          communicat_o__AccountSid__c,
                          communicat_o__EndPoint__c,
                          communicat_o__FromPhNumber__c,
                          communicat_o__Token__c,
                          communicat_o__Version__c
                          FROM communicat_o__API_Credentials__mdt
                          WHERE developername = 'Twilio'
                          LIMIT 1];
        accountSid = apiCredentials[0].communicat_o__AccountSid__c;
        token = apiCredentials[0].communicat_o__Token__c;
        fromPhNumber = apiCredentials[0].communicat_o__FromPhNumber__c;
    }
    
    public void processSms(){
        if (!(listComActivity.IsEmpty()))
            for (communicat_o__Communicat_O_activity__c comActivity : listComActivity){
                HttpRequest req = new HttpRequest();
                req.setEndpoint(apiCredentials[0].communicat_o__EndPoint__c + accountSid+'/SMS/Messages.json');
                req.setMethod('POST');
                String VERSION  = apiCredentials[0].communicat_o__Version__c;
                req.setHeader('X-Twilio-Client', 'salesforce-' + VERSION);
                req.setHeader('User-Agent', 'twilio-salesforce/' + VERSION);
                req.setHeader('Accept', 'application/json');
                req.setHeader('Accept-Charset', 'utf-8');
                req.setHeader('Authorization','Basic '+EncodingUtil.base64Encode(Blob.valueOf(accountSid+':' +token)));
                req.setBody('To='+EncodingUtil.urlEncode(phNumber,'UTF-8')+'&From='+EncodingUtil.urlEncode('+' + String.valueOf(comActivity.communicat_o__Phone_Number__c),'UTF-8')+'&Body='+comActivity.communicat_o__Message__c);
                Http http = new Http();
                HTTPResponse res = http.send(req);
                System.debug(res.getBody());
                if(res.getStatusCode()==201)
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'SMS Sent Successfully'));
                    system.debug('SMS Sent Successfully');
                
                else{
                    
                    erw =(errorResponseWrapper)json.deserialize(res.getBody(),errorResponseWrapper.class);
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,erw.message));
                    system.debug('erw' + erw.message);
                }
                
            }
    }
    public void execute(QueueableContext ctx) {
        this.processSms();
    }
    
    public class errorResponseWrapper{
        
        String code;
        String message;
        String moreInfo;
        String status;    
        
    }
    
    
}

 
  • April 06, 2019
  • Like
  • 0
Can anyone please help me with making the javascript code reusable?
There is almost same piece of code in both the functions.
Please provide the snippet
({
    sendLater : function(component, event, helper) { 
        var recId = component.get("v.recordId");
        console.log(recId);
        var smsBody = component.get("v.selectedTemplateBody");
        console.log(smsBody);
        var scheduleDateTime = component.get("v.scheduleDateTime");
        console.log(scheduleDateTime);
        $A.util.toggleClass(component.find("mySpinner"),"slds-show");
        var action = component.get("c.sendLaterButton");
        console.log(action);
        action.setParams({ 
            scheduleDateTime :   component.get("v.scheduleDateTime"),
            message          :   smsBody,
            recordId         :   component.get("v.recordId"),
            objName          :   component.get("v.sObjectName")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                
                $A.util.toggleClass(component.find("mySpinner"),"slds-hide");
                var toastEvent = $A.get("e.force:showToast"); //
                /**/
                toastEvent.setParams({
                    title: "Success!",
                    message: "The record has been created successfully ."
                    
                });
                toastEvent.fire();
                var modal = component.find("Modal");
                $A.util.addClass(modal, 'hideDiv');
                var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                dismissActionPanel.fire(); 
                
                
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                        dismissActionPanel.fire(); 
                        var toastEvent = $A.get("e.force:showToast"); // //
                        toastEvent.setParams({
                            title: "Failed",
                            message: "The record was not saved"
                            
                        });
                        toastEvent.fire();
                    }
                } 
            }     
        });
        $A.enqueueAction(action);
    },
    
    sendNow : function(component, event, helper) { 
        var recId = component.get("v.recordId");
        console.log(recId);
        var smsBody = component.get("v.selectedTemplateBody");
        console.log(smsBody);
        var scheduleDateTime = component.get("v.scheduleDateTime");
        console.log(scheduleDateTime);
        $A.util.toggleClass(component.find("mySpinner"),"slds-show");
        var action = component.get("c.sendNowButton");
        console.log(action);
        action.setParams({ 
            scheduleDateTime :   component.get("v.scheduleDateTime"),
            message          :   smsBody,
            recordId         :   component.get("v.recordId"),
            objName          :   component.get("v.sObjectName")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                
                $A.util.toggleClass(component.find("mySpinner"),"slds-hide");
                var toastEvent = $A.get("e.force:showToast"); //
                /**/
                toastEvent.setParams({
                    title: "Success!",
                    message: "The record has been created successfully ."
                    
                });
                toastEvent.fire();
                var modal = component.find("Modal");
                $A.util.addClass(modal, 'hideDiv');
                var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                dismissActionPanel.fire(); 
                
                
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        var dismissActionPanel = $A.get("e.force:closeQuickAction"); 
                        dismissActionPanel.fire(); 
                        var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title: "Failed",
                            message: "The record was not saved."
                            
                        });
                        toastEvent.fire();
                    }
                } 
            }     
        });
        $A.enqueueAction(action);
    }
})

 
  • March 14, 2019
  • Like
  • 0
Hi,

I am creating a lightning component which will display the list view for a custom component. 
Can anybody please tell me how do i add filters,inline editing and mass update action for it ?

Thanks
  • March 13, 2018
  • Like
  • 0
Hi,
i am getting a post call out from external stsyem. i am creating or updating a  custom object record out of it. Can anyone please let em know how to write a test classs for it?
Here is my code:

global without sharing class ContactService {
    
    @HttpPost
    global static String insertContact(ContactInfoParser contactRec){
        //creation or update of application record. Mapping the fields from ContactInfoParser class.
        String RecordTypeApplicationId = Schema.SObjectType.Application__c.getRecordTypeInfosByName().get('Test').getRecordTypeId();        
        Application__c applicationObj = new Application__c();
        applicationObj.Id = contactRec.application.applicationId;
        applicationObj.applicant__c = contactRec.contact.contactId;
        applicationObj.RecordTypeId = RecordTypeApplicationId;
        applicationObj.assessPriorLearning__c = contactRec.application.assessPriorLearning;
        applicationObj.Status__c = contactRec.application.status;
        applicationObj.reason__c= contactRec.application.reason;
        applicationObj.priorLearningNotes__c= contactRec.application.priorLearningNotes;
        applicationObj.applingForCredit__c= contactRec.application.applingForCredit;
        upsert applicationObj;


Thanks
  • March 09, 2018
  • Like
  • 0