• Suraj P
  • NEWBIE
  • 360 Points
  • Member since 2014
  • Salesforce Solution Architect

  • Chatter
    Feed
  • 11
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 63
    Replies
Hello.  I am getting a very simple JSON response back but can't seem to deseralize it correctly to get the ID that I need.  The response looks like this:

{
    "duration": 0.024,
    "success": true,
    "error_message": null,
    "status_code": 201,
    "payload": {
        "id": "XXXXXXXXXXXXXXX",
        "name": "test4204201112"
    }
}


My apex looks like this:

 if(res.getStatusCode() < 300){
            Type resultType = Type.forName('ResponseModel'); 
            ResponseModel r1 = (ResponseModel)JSON.deserialize(responseJSON1, ResponseModel.class);      

         }
        
    }
    

    public class ResponseModel{
        
        public decimal duration;
        public boolean success;
        public string error_message;
        public integer status_code;
        public string payload;
        public list<string> id;
        public list<string> Name;
     
    }



Of course this doesn't work.  I think the whole list thing is wrong.  Since payload is a JSON object, I'm having trouble getting that ID out of it.  All I need is that ID.  Can anyone help and change my code so that it works?  

I've also tried making another class for payload and deseralize it again to there, but no luck. 

 
Hello,

I'm new to Salesforce Apex. I keep getting this error message when I try save my code eventhough I've declared the variable already..

User-added image

Compile Error: Variable does not exist: BTLog at line 16 column 33    ​
Trigger AutocreateBTWeightRecordsAndMatchitToAccount on bodytrace__c (after insert) {
    for (BodyTrace__c BTLog : Trigger.new) {
    
    Bodytrace_weight__c BTWeight = new Bodytrace_Weight__c();
 
    BTWeight.IMEI__c             =  BTLog.IMEI__c;
    BTWeight.Weight__c           =  BTLog.Values_weight__c;
    BTWeight.Date_of_reading__c  =  BTLog.CreatedDate;
    BTWeight.bodytrace_log__c    =  BTLog.ID;
         
    Insert BTWeight;
      
    }
    
        For (Account Accnt : Trigger.new) {
            if(accnt.IMEI__c == BTLog.IMEI__c){
            BTWeight.Account__c = account.ID;
            }
        }
}
Background on what I'm trying to do:

I'm trying to build a trigger that create a weight reading records (Bodytrace_Weight__c) based of weight logs records (Bodytrace_Weight__c). After that I'd like to auto-assign (Bodytrace_Weight__c) to the patient who got weighted based on the serial number that is found on both; account object and Bodytrace_Weight__c object.

Please let me know what's the best way to build this. Thanks!
I have a custom object that logs events for each account. It's set up as a master-detail and works just fine. However, I'd like to extract the total number of events for this year and for this month. I have the following SOQL query:

SELECT COUNT()
FROM  EventLog__c
WHERE Account__c = 'XXXXXXXXXXXX'
AND Time_Stamp__c = THIS_MONTH

This works fine, but is there a way to get the count for the current year in the same query, or do I have to submit a 2nd query using THIS_YEAR?

(p.s. I'm using REST API to submit the query - not Apex - although I'm not sure it matters.)

-Steve
 
Hi,
I am stuck with the width of modal window pos up when someone clicks on a quick action. I saw there is a option to adjust the height.
But i am not able to adjust the width of modal window at all. Tried all possibilities.

Kindly help me on this.
I have a simple apex controller extension and created a basic unit test to verify the returned page reference from the controller is expected value.
When I run the test I get failure with below message - clearing showing the values do match???

System.AssertException: Assertion Failed: Page Reference should be for the Opportunity:
Expected: System.PageReference[/0065B000007l82WQAQ],
Actual: System.PageReference[/0065B000007l82WQAQ]

Here is test code:
     @isTest
     static void testOppContractCreateNotCreated() {   /* opportunity stage is not set to correct value for contract create */
        setupTestData();
        PageReference expectRef = new PageReference('/' + opp.Id);
          Test.startTest();
                stdCont = new ApexPages.Standardcontroller(opp);
            contExt = new OpportunityCreateContractContExt(stdCont);  
             PageReference createContractPageRef = Page.createAdSalesContract;
            Test.setCurrentPage(createContractPageRef);
            PageReference goToRef = contExt.getgoToContract();
            system.debug(opp);
            system.debug(goToRef);            
         Test.stopTest();
        system.assertEquals(expectRef, goToRef,'Page Reference should be for the Opportunity');
     }
  • July 06, 2017
  • Like
  • 0
Hey!

I'd like to purge all objects not matching certain field values.

Is it possible to create a batch class removing all tasks older than a certain date, except the task with an ID matching an Account field "Task ID"? This would leave 1 task with ID = Account.TaskID.

Thanks for any help!
Need advise for any possible custom coding or alternative solution for hiding an opportunity record from the owner.Any help is most appreciated.
All,
I have a requirement to update a trigger to include Trigger.OldMap so that if a user edits a completed task, it doesn't fire the trigger again. Once I added Trigger.OldMap to the trigger, my test coverage went from 95% to 0%. Adding an Update to the inserted Task in the test code does not seem to help either. Below is my code:

Trigger:
trigger SalesBlitzProcess on Task (after insert, after update) {
    if(!RecursiveTriggerHelper.isAlreadyModified()){
        RecursiveTriggerHelper.setAlreadyModified();{
            Task[] taskOldList = trigger.IsDelete ? null : trigger.old;
            Task[] taskNewList = trigger.IsDelete ? trigger.old : trigger.new;
            if(trigger.oldMap != null) {
                for(task tsk: trigger.new) {
                    if(tsk.isClosed && trigger.oldMap.get(tsk.Id).isClosed == false){
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeLeftMessage();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeContinueProcess();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeNotNow();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeHardNo();
                    }
                }
            }
        }
    }
}



Class
public class SalesBlitzProcess {
    //Grab List of tasks
    protected final Task[] taskNewList;
    protected final Task[] taskOldList;
    
    public SalesBlitzProcess (Task[] taskOldList, Task[] taskNewList){
        this.taskNewList = taskNewList;
        this.taskOldList = taskOldList;
    }
    
    List<Task> taskList = new List<Task>();
    List<Opportunity> oppList = new List<Opportunity>();
    Task t;
    Opportunity o;
    Contact c;
    Account a;
    
    //Left Message - Create new Tasks if the following Outcomes == 'Left Message' || 'No Answer'
    Set<Contact> cSet = new Set<Contact>();
    public void executeLeftMessage(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 1' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = True; and c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    c.Send_Day_1_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 3';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 3' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 5';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 5' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Send_Day_5_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 8';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(3);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 8' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    c.Send_Day_1_Follow_Up_Email__c = false;
                    c.Send_Day_5_Follow_Up_Email__c = false;
                    cSet.add(c);
                }
            }
        }
        
        If(!taskList.isEmpty()){
            insert taskList;
        }
        If(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    
    //Continue Process - Create Opportunity if Task has the following outcomes
    Set<Id> ContactIds = new Set<Id>();
    public void executeContinueProcess(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Set First Advisor Briefing'
                                            || tsk.Outcome__c == 'Set Qualified Meeting'
                                            || tsk.Outcome__c == 'Set Existing Producer Meeting'
                                            || tsk.Outcome__c == 'Set Touch Base Meeting'
                                            || tsk.Outcome__c == 'Proposal Needed'
                                            || tsk.Outcome__c == 'Verbal Commitment')){
                                                String tId = tsk.WhoId;
                                                if(String.ValueOf(tsk.WhoId).substring(0,3) == '003'){
                                                    ContactIds.add(tsk.WhoId);
                                                }
                                            }
        }
        if(!ContactIds.isEmpty())
        {
            Map<Id, Contact> cIdMap = new Map<Id, Contact>([Select Id, AccountId, Account.Name, Nurture_Paused__c FROM Contact Where Id in:ContactIds]);
            Set<Id> accountIds=new Set<Id>();
            for(Task tsk : taskNewList)
            {
                if(tsk.WhoId != null && cIdMap.get(tsk.WhoId) != null){
                    //o.AccountId = cIdMap.get(tsk.WhoId).AccountId;
                    accountIds.add(cIdMap.get(tsk.WhoId).AccountId);
                }
            }
            
            if(!accountIds.isEmpty())
            {
                Map<Id,Account> mapAccount=new Map<Id,Account>([SELECT Id, (SELECT Id FROM Opportunities) FROM Account where Id IN : accountIds]);
                for(Id accId:accountIds)
                {
                    if(mapAccount.containsKey(accId))
                    {
                        if(mapAccount.get(accId).Opportunities.size() == 0)
                        {
                            Opportunity opp=new Opportunity();
                            opp.Name = 'New Sales Blitz Opportunity';
                            opp.AccountId = accId;
                            opp.StageName = 'New';
                            opp.Opportunity_Potential__c = 0.00;
                            opp.CloseDate = Date.today();
                            opp.OriginalOpportunitySource__c = 'Sales Blitz';
                            oppList.add(opp);
                        }
                    }
                }
                
            }
        }
        If(!oppList.isEmpty()){
            insert oppList;
        }
    }
    
    //Not Now - Check Nurture Paused for 3 weeks if Outcome__c == Follow Up Or TBD, then unpause.
    public void executeNotNow(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Follow Up' || tsk.Outcome__c == 'TBD')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = '005F0000004E8iS';
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Weeks';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(21);
                taskList.add(t);
            }
            //After 3 weeks, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Weeks' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    //Hard No - Create reminder task to close in 90 days to unpause nurture
    public void executeHardNo(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Outcome__c == 'Not Interested' && tsk.Subject.contains('Sales Blitz')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = '005F0000004E8iS';
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Months';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(90);
                taskList.add(t);
            }
            //After 3 months, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Months' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
}

Test Class
@isTest
private class testSalesBlitzProcess {
    
    static testMethod void LeftMessage1(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 1';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
        static testMethod void LeftMessage1TESTNULL(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 1';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = null;
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        test.startTest();
        tsk.Status='Completed';
        update tsk;
        test.stopTest();
        
         System.assertEquals(tsk.Status = 'Completed', null);
    }
    
    static testMethod void LeftMessage2(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 3';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
    static testMethod void LeftMessage3(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 5';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
    static testMethod void LeftMessage4(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 8';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
    static testMethod void notNow1(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Weeks';
        tsk.Outcome__c = 'Follow Up';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void notNow2(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Weeks';
        tsk.Outcome__c = 'TBD';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void notNow3(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Weeks';
        tsk.Outcome__c = 'Unpause Nurture';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void HardNo1(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Months';
        tsk.Outcome__c = 'Not Interested';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
        static testMethod void HardNo2(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Months';
        tsk.Outcome__c = 'Unpause Nurture';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void testOpportunity1(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set First Advisor Briefing';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity2(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set Qualified Meeting';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity3(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set Existing Producer Meeting';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity4(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set Touch Base Meeting';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity5(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Proposal Needed';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity6(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Verbal Commitment';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
}
I am having a text field on a user object. which holds values like(Not always) salels,services,marketing,HR,threat and sometimes just sales.
I am having a picklist field on account object which holds above values.....and only one is selected each time.
Based on both the fields i am trying to get id of object and use it on my account object.I am using that field in a trigger.

For example,my values in text field are services,marketing.when user selects marketing on account picklist,i need to check that on user's  and get id of user and use it for my further logic.

Below is my trigger.It works fine in above condition.

But when user selects HR from picklist and two users are having value HR and Threat in custom field.It is considering both the userids.
trigger updateuserdataonaccount on account(before insert,before update){
    Set<String> accrecords= new Set<string>();
    for(account pr : Trigger.new)
    {   
      if(string.isnotblank(pr.picklistfield))
     accrecords.add('%' + pr.piclistfield+'%');
    }
    
     Map<String,Id> mapTOSToUserId = new map<String,Id>();
    
    for(User u : [Select id,customtextfield__c from user
                  where customtextfield__c Like : accrecords])
    {
        for(String strService : accrecords)
        {
        strService = strService .substring(1,strService .length()-1);
    
            if(u.customtextfield__c .containsIgnoreCase(strService))
            {
            mapTOSToUserId.put(strService, u.Id);
            break;
            }
        }
    }
    for(account acc : Trigger.new)
        {   
   //Rest of trigger logic
        }
}



 
When saving a new opportunity or adding further products to an opportunity the fields below appear.  Where is it possible to edit the fields that appear here? 

Add Products to Opps
Hello,

Can anyone help me on this validation rule causing CPU timeouts. When load the data through dataloader this validation is causing the CPU time out error, if I deactivate this rule and the load is success with no CPU timouts. I tried multiple times and noticed the same results. Is there a betterway we can write this validation rule?

AND ( 
OR($Profile.Name <> "API Integration", $Profile.Name <> "USA Sales Planning Rep",$Profile.Name <> "USA Sales Planning Executive",$Profile.Name <> "USA Sales Planning Mgr",$Profile.Name <> "API Eloqua" ), 
OR( 
ISBLANK( BillingCity ), 
ISBLANK( BillingStreet ), 
ISBLANK( BillingCountry), 
ISBLANK( BillingState), 
ISBLANK( BillingPostalCode ) 

)
I am trying to load a static resource in a lightning component using lightning:container. My org has a namespace, which is common for both the static resource and the lightning component. However, the resource is not loading. The browser says that it "Cannot find the Site" within the lightning:container iFrame. Has anyone been able to load a static resource in a lightning:container in a namespaced org?
I'm faced with this generic error when trying to create a package version using sfdx second generation packaging. Any thoughts?

An unexpected error occurred. Please contact Salesforce Support and provide the following error code: 77380607-2684 (-1373703285)
I built a process builder triggered by a platform event that works on multiple records, triggering a flow in turn for each record. I assumed that like a regular record create/update triggered Process Builder Flow, Salesforce would batch up the invocations, but, to my suprise, I find that Salesforce invokes the flow one at a time and, eventually, throws a "Number of Iterations exceeded" error. Am I missing something here?
I was trying to use JS WebWorkers for a long running process in my component and got the message that the 'Worker' constructor is invalid. Is there a workaround to this?
I'm getting the following error when trying to create a new package version using Salesforce DX and packaging2. Is there any documentation regarding this?
I am trying to build a CTI adapter. But I keep getting the error: "Failed to construct 'WebSocket': Please use the 'new' operator, this DOM object constructor cannot be called as a function.". Is this a know limitation?
I have created a ContentDocument and ContentDocumentLink against the parent object record. However, AttachedContentDocuments related list for the record is still empty. It works successfully, outside of a test class (via Anonymous Apex, for instance) . Any ideas would be appreciated.
I'm trying to retrieve Account records in my Visualforce page using Remote Objects. However, when I attempt to query for records with a null value for BillingLatitude, I get an error. Apparently, any value I type in the critieria is being interpreted as a String since the error message shows quotes around the values. Any ideas?

The following ways don't seem to work:
new SObjectModel.Account().retrieve({where:{BillingLatitude:{eq:null}}});
new SObjectModel.Account().retrieve({where:{BillingLatitude:{eq:''}}});
I understand that when using OpenCTI in place of regular CTI, we have to design and build our own custom Softphone layouts from scratch. Ar there any Javascript, CSS libraries/plugins available out there to jumpstart this process? Or is there a better way that I'm missing here?

Thanks!
I am trying to build a hybrid app with offline support for images. Smartsync doesn't seem to want to download the actual image blob data ('VersionData' field from 'ContentVersion') in my case, and I have been trying to accomplish that with forcetk, by retrieving the VersionData field by itself. But even forcetk seems to want to download only the URL and not the actual blob data. Any suggestions, guys?
Hello

We use /services/data/v47.0/sobjects call fetch all objects and show it in reporting but not able to find one object created by me and have full permissions.

Can you suggest what needs to be checked?
Hello,
I am trying to open a static ressource for a Aura Component. A company that programs components in SF for us, made a component with an Static Ressource. I need to add a class there but when I download the file (Setup- Static Ressources- Detail to static Ressource - show file) it has no file-extension. It is only "AuraServiceHelper". When I open the file with any programm/ or when I change the extension to .js/ .html etc. I get a salad of symbols. (£“̳Àã»\7²§ŸC20ëdœ&ã¿RÓe)

Can anyone say me, how I can edit this file right?

Name: AuraServiceHelper
Namespace-Präfix: -
Description: Contains javascript helper method to access AURA API faster in lightning components
MIME-Typ: application/octet-stream
Cache-Steuerung: Privat
Größe: 3.871 Byte

Thanks in advance,
Hello.  I am getting a very simple JSON response back but can't seem to deseralize it correctly to get the ID that I need.  The response looks like this:

{
    "duration": 0.024,
    "success": true,
    "error_message": null,
    "status_code": 201,
    "payload": {
        "id": "XXXXXXXXXXXXXXX",
        "name": "test4204201112"
    }
}


My apex looks like this:

 if(res.getStatusCode() < 300){
            Type resultType = Type.forName('ResponseModel'); 
            ResponseModel r1 = (ResponseModel)JSON.deserialize(responseJSON1, ResponseModel.class);      

         }
        
    }
    

    public class ResponseModel{
        
        public decimal duration;
        public boolean success;
        public string error_message;
        public integer status_code;
        public string payload;
        public list<string> id;
        public list<string> Name;
     
    }



Of course this doesn't work.  I think the whole list thing is wrong.  Since payload is a JSON object, I'm having trouble getting that ID out of it.  All I need is that ID.  Can anyone help and change my code so that it works?  

I've also tried making another class for payload and deseralize it again to there, but no luck. 

 
Within the application ive built, i capture a start date and an end date on an opportunity.  I can now show a visual of when things are due to start and due to end, but the question i'm now being asked is can we tell how many concurrently are running.

So as an example i have Opportunity 1, with a start date of 20/1/01 and an end date of 20/6/01, but i want to find out what's running on 20/03/01.  Any ideas on the best way to model the data or build the logic in order to achieve this.  The outcome would be a dashboard report which shows by month how many we have running ie it's past the start date but not past the end date.

Thanks in advance!

Good Day Salesforce Developer Community.

I have a small custom component that we are using lightning:picklistpath.  We are using it in a community to show the progress of a case (like a Domino's pizza tracker)   I have created a custom picklist that holds the values I want to share with the customer and I have a process builder that fires to keep the new custom picklist updated with the correct value.  

The issue I am having is that all of the prior cases that do not have a value in my new custom picklist do not display the correct stage in the picklistpath becuse there is no value yet.  I know I can use dataloader to update the still open cases but that would adjust the last modified date and could have impact to reporting. 
 

What I would like to do is when the Lightning component loads, go and update the custom picklist to the correct value.  Is there fairly easy way to do this on initation of the component?  I need it to do it without engaging validation and required fields. that could prevent me from saving the record.  

Any help would be greatly appreciated.

I have been tasked with something from management and am stumped.  We have a process in place for our sales reps when scheduling QBR's (Quarterly Business Reviews) in outlook to have certain words in the subject and their calendar sync's with Linkpoint that it creates a Calendar Event.  That is all working fine.  From here is where I am stuck, I need to have a field on the account page and populate it with the value of that events start date.  For the life of me, I cannot figure out how to do this.  I tried building a new field as a formula but I don't have access to the activities fields. Is it possible to use the values of event fields to populate other fields?  The event is associated with the contact and the contact is associated with the account.  Thanks in advance. 
I am trying to complete the Set Up Your Salesforce DX Environment module.  I have successfully created a test DX account and have installed the CLI (Windows x64 bit).  However, when I try and complete the next step, by entering sfdx force:auth:web:login -d -a DevHub into the command prompt, the browser (Chrome) asks me to login which I enter my credentials, but then when I click the Login button, the browser appears like it's going to a new page, but then it displays a page with a "This page isn't working localhost didn't send any data." error and the command prompt displays "ERROR: self signed certificate in certificate chain."

Does anybody know what I am doing wrong on getting to complete this step of the module?  Thanks.
These are my current setup
- 1 custom controller
- 2 vf pages using the same custom controller
- 2 custom objects where page 1 uses object 1 and page 2 uses object 2(User inputs data for object 1 in page 1 and object 2 in page 2)

My requirement is, I should be able to move back and forth between page 1 and 2, and I should be able to hold the data entered by the user when moving between pages. Note: The user haven't saved the data yet when moving between pages. 
 
public class customController{

public Object1__c object1{get;set;}

public Object2__c object2{get;set;}

public customController()
{
       Id id = ApexPages.currentPage().getParameters().get('id');

       this.object1=(id == null) ? new Object1__c () :[select field1__c,field2__c from Object1__c where Id=:id ];

       //will this work and is it correct??
       this.object2=(id == null) ? new Object2__c () [select field3__c,field4__c from Object2__c where Id=:id ];
}


I have shared a sample of the logic I have written to retrieve the data in the constructor. Apparently, this seems to work and the data is still available when moving between pages, but is this correct?(I am using a single variable "id" to retrieve data from last page for both objects) And I am unable to write a test class, because it fails in the constructor

I have been fiddling around with creating Alexa Skills that access the Salesforce API recently. Anything that doesn't require authentication is working fine, but it is the account linking that I am having issues with.

I have a connected app set up in a way that I assume is correct.
User-added image
And I've got all of the account information in the Alexa configuration. I have the Authorization URL pointing at the OAUTH service with the redirect_uri in the url params. I have the Client_Id set to the Consumer Key from the connected app, and for Authorization Grant Type I have 'Auth Code Grant' selected, with the Access Token URI set to the same as the Authorization URL, the Secret set to the secret from the connected app, and I've tried both options for the client authentication scheme.

When I go to Alexa.Amazon.com and try to link the skill, it brings me to my Community login page, and accepts my credentials. But when it;s done it redirects to my community site instead of back to Amazon, and when I click on Link Account again, it just gives me an error page saying 'Unable to link your skill, try again later'.

Any help would be appreciated, I've been banging my head against a wall for a couple weeks now trying to get the account linking to work, to no avail.

Hello,

I'm new to Salesforce Apex. I keep getting this error message when I try save my code eventhough I've declared the variable already..

User-added image

Compile Error: Variable does not exist: BTLog at line 16 column 33    ​
Trigger AutocreateBTWeightRecordsAndMatchitToAccount on bodytrace__c (after insert) {
    for (BodyTrace__c BTLog : Trigger.new) {
    
    Bodytrace_weight__c BTWeight = new Bodytrace_Weight__c();
 
    BTWeight.IMEI__c             =  BTLog.IMEI__c;
    BTWeight.Weight__c           =  BTLog.Values_weight__c;
    BTWeight.Date_of_reading__c  =  BTLog.CreatedDate;
    BTWeight.bodytrace_log__c    =  BTLog.ID;
         
    Insert BTWeight;
      
    }
    
        For (Account Accnt : Trigger.new) {
            if(accnt.IMEI__c == BTLog.IMEI__c){
            BTWeight.Account__c = account.ID;
            }
        }
}
Background on what I'm trying to do:

I'm trying to build a trigger that create a weight reading records (Bodytrace_Weight__c) based of weight logs records (Bodytrace_Weight__c). After that I'd like to auto-assign (Bodytrace_Weight__c) to the patient who got weighted based on the serial number that is found on both; account object and Bodytrace_Weight__c object.

Please let me know what's the best way to build this. Thanks!
I have a custom object that logs events for each account. It's set up as a master-detail and works just fine. However, I'd like to extract the total number of events for this year and for this month. I have the following SOQL query:

SELECT COUNT()
FROM  EventLog__c
WHERE Account__c = 'XXXXXXXXXXXX'
AND Time_Stamp__c = THIS_MONTH

This works fine, but is there a way to get the count for the current year in the same query, or do I have to submit a 2nd query using THIS_YEAR?

(p.s. I'm using REST API to submit the query - not Apex - although I'm not sure it matters.)

-Steve
 
We have a custom object "Recognition" related to Contacts. This helps us track our employees and if they were recognized for performance each month. If I am recognized during June 2017, I will get a Recognition record created with custom field Date Issued = 6/30/17 (We always list it as the last day of the month for that month) and Recognition checkbox = True. I need to create a field on the Contact object that evaluates for only those who have a recognition during the prior month, how many consecutive months prior they have been recognized. Example:

Jane Smith has recognition for:
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017

John Smith has recognition for:
- June 2017
- April 2017
- March 2017
- February 2017
- January 2017

Bob Smith has recognition for:
- March 2017
- February 2017
- January 2017

This field would then evaluate to the following:
Jane Smith - 5 (Last 5 Months but not the 6th prior month)
John Smith - 1 (Last Month but not two months ago)
Bob Smith - 0 (Not Last Month)

I think this can be done through apex but I'm not a true developer so I wouldn't be able to write it myself. I would need it to basically look through all the recognitions and find the most recent month they didn't have one where recognition (checkbox) = true and count the number that have occurred since then.

Any suggestions/help would be appreciated.

Doug
Hey,

I'm trying to figure out how to create a trigger to delete all but the most recent task. Is it possible to order and remove all but most recent?

My actual use-case is this:

For tasks with subject "AAA" on Account "B1", If any task exists with created date < 30 days, purge all tasks with created date >/_ 30 days.
For tasks with subject "AAA" on Account "B1", If no task exists with created date < 30  days, keep most recent task, purge all others.

I'd do the same for tasks with subject not equal to "AAA". Meaning if no task exists with created date <30 days, an account may show the most recent task with subject "AAA" and most recent task with subject "BBB", with older tasks of both subjects purged.

I'm having trouble finding much on this niche use-case, and I'm unsure if it's possible to order tasks by ID or creation date and delete all but the most recent from there.

Thank you very much for your help.

Patrick
Hi everybody,

I need to define a Web Service in Apex in order to connect Salesforce with an external system that is allocated in a private network. This system has been working for years and our client has suggested us to be as less intrusive as possible. Their suggestion is provide us with a VPN in order to access to its webservice endpoint.

I've been looking for Salesforce documentation regarding VPN connection and I haven't found anything at all. All I have found regarding this topic is a post in a forum where they said that it's not possible to define a VPN connection in Salesforce.

Does anybody knows how to define this process? If it is not possible, anybody knows an alternative different from (a) transform the private Web Service into a public one or (b) define a public intermediate layer?

Thank you very much for your help,
Alex

Hi!

 

I'm trying to get the existing ID when a DmlException: DUPLICATE_VALUE is throw.

but i'm getting null.

my code looks like this: 

Case c = new Case();
//set some fields
try{
  insert c;
}catch(DmlException e){
  if(e.getDmlType(0) == StatusCode.DUPLICATE_VALUE){
    return e.getDmlId(0); //its null here! =(
  }else{
    throw e;
} } return c.id;

 

I could to put a

c = [Select id from Case where other_fields = other_values];

but i can't be sure if it will get the same record.

 

If I check the logs i find: 

System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Claim_id__c duplicates value on record with id: 500J0000001ylwB: []

 

Any ideas how do i get the id without manipulating the message string? 

500J0000001ylwB