• Rishabh Patel 1
  • NEWBIE
  • 75 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 11
    Replies

I am trying to pass two variables from Flow to apex. One is a collection variable and another is just a string. 

Collection Variable is passed in personIds

And Passing String in inputName

I am trying to loop on the  Collection variable and update the name, But  i am not able to access the input name, as i can only create one method for personIds. 

global class lookupflowvars {
public with sharing class Requests {
  @InvocableVariable(label='Records for Input' description='test' required=true)
  public string inputName;
  }

   
     @InvocableMethod(label='Update Person Member Reference' description='Update MemberReference field on Person')
         
    
    public static void UpdatePersonMemberReference(List<List<String>> personIds){
   
    List<String> values = new List<String>();
    for (List<String> subList : personIds) values.addAll(subList);
         // List<Id> oppids= new List<Id>(); 
        List<Opportunity> oppList = new List<Opportunity>();
        oppList = [select id,Name__c from opportunity where id in :values];
        for (Opportunity newopplist : oppList ){
        newopplist.Name__c =inputName';   //cannot access  inputName here!
        update newopplist;
        }

    }
     
    
}

Cannot access inputName

Hello, I already have a Schedule apex, that works on 3 objects to do a basic Query and update. I wanted to make this class batch. But unable to add multiple objects in Batch apex and loop around them . 

Here is how my Schedule apex looks like 

global class scheduleWorkday implements Schedulable {
   
 global void execute(SchedulableContext ctx) {

  //Get Accounts
        
        List<Account> getbdayaccount = [Select ID, Name, Address from Account where State= CT];
        
        if(!getbdayaccount .isEmpty()) {
                for(Account a : getbdayaccount ) {
                a.name = 'Test';
                a.State= 'NJ';
            }
            update getbdayaccount ;
        }

//get Leads 

   List<Lead> getPreApprovalFollow = [Select ID, Name, State, LeadSource from Lead where State = 'CT' ];
        
        if(!getPreApprovalFollow .isEmpty()) {
               for(Lead l: getPreApprovalFollow ) {
                l.LeadSource = 'Referral';
                l.State = 'NJ';
            }
            update getPreApprovalFollow ;
        }

//get Opportunities 

List<Opportunity> getopps = [Select Id, CloseDate, State from Lead where State = 'CT'];

   if(!getopps.isEmpty()){
     for(Opportunity o : getopps){
     o.CloseDate = Date.Today();
      o.State = 'CT';
}
update get opps;


}



}


}


I  tried making batch apex something like this - 

global class LeadProcessor implements Database.Batchable <SObject> {
//START METHOD
    global Database.QueryLocator start(Database.BatchableContext bc){
        String Query='Select id,LeadSource, State from Lead where state = 'CT'';
        return Database.getQueryLocator(Query);
            }
//EXECUTE METHOD
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        for(Lead l: scope){
            l.LeadSource='Referral';
            l.State = 'NJ';

        }
        update scope;
    }
//FINISH METHOD
    global void finish(Database.BatchableContext bc){
       
    }
}


How can I change this batch apex to return multiple queries and update them . 

 

Thank you

I have an apex class that gets the Leads from the Query in the metadada and does some basic updates on leads and adds them in campaign 

The class is working fine, But I wanter to make is Batchable in case I get more than 100 records. 

Here is my apex class  - 

public with sharing class leadtester implements Schedulable   { 
 public list<Lead>  quo{get;set;}

public void execute(SchedulableContext ctx){ 
     Leads__mdt [] leadVals = [SELECT Final_Query__c FROM Leads__mdt ];
     
     
     list<Leads__mdt> u = [SELECT 
 Retention_Updated_Queue__c,Add_to_Campaign__c FROM Leads__mdt  ]; 
        
     quo= Database.query(leadVals[0].Final_Query__c );

        for(Lead ldt :quo){
      if(ldt != null ) {
       //Update those leads with new owner ID
       string test  = ldt.OwnerId;
       list<Group> v = [Select name from Group where ID  =:test]; 
       ldt.Previous_Lead_Owner__c = v[0].name;
       ldt.Lead_Status_at_Last_Retention__c = ldt.Status;
       ldt.OwnerId = u[0].Retention_Updated_Queue__c;
       ldt.Last_Retention_Date__c = Datetime.now(); 
       ldt.Retention_Count__c = ldt.Retention_Count__c +1 ; 
        if(u[0].Add_to_Campaign__c !=Null){  
       CampaignMember mem = new CampaignMember (campaignid=u[0].Add_to_Campaign__c, leadid=ldt.id);
        
        database.insert (mem, false);
        }
        }
        update quo;
        }
        }
        
}

I am doing a SOQL query and then updating records. The trick here is . I am grabbing my query from two custom fields which are in the Custom Settings . My code works fine records are getting queried and updated. I am having big trouble in making test class for this . Help is appriciated . Here is my Apex Class -

public with sharing class textInputsConsecond implements Schedulable   { 
 public list<Lead>  quo{get;set;}


 public void execute(SchedulableContext ctx){ 
   quo= Database.query(Lead__c.getInstance().Database_Query__c + 
   Lead__c.getInstance().Database_Query2__c);
   for(Lead ldt :quo){
   //Update those leads with new owner ID
   ldt.OwnerId = '00G3B000001hp6VUAQ';

    }

   update quo;
 }
 }


Here is the screenshot of my Query in the Field in custom settings -

User-added image

So my query is basically Database Query field + Database Query2 Field

The only reason to use two fields is salesforce is not allowing text box more that 255 characters  

I have an Apex class on  Custom Object Called QueueDistroHelper__c 

What I am basically doing is getting the Queue Id from a custom field(Related_Queue_Id__c) on the Custom object 

Querying all the users in that queue

And updating another custom field(Queue_Members__c )  with all the users in that Queue 

My apex class is working fine  

Here is the apex class  - 

global class lookUpAccountAnnotation {
public class inputValues{
        @InvocableVariable(label='Queue ID' )
        public string QueueId;
        @InvocableVariable(label='Record Id' )
        public Id recordid;
        public string temp;
    }
   @InvocableMethod
    public static void deletePackageLicense(List<inputValues> inputs){
    
      for (inputValues i : inputs)
   {
     List<QueueDistroHelper__c> getcurrentobject =  [SELECT Queue_Members__c ,  Next_Queue_Reassignment_User__c  FROM QueueDistroHelper__c WHERE Id=:i.recordid ];
     
      List<User> users =  [SELECT
                    name
                FROM
                    user
                WHERE
                    id IN ( SELECT userOrGroupId FROM groupmember WHERE groupId =:i.QueueID)
                    AND
                    isActive = true
               
                ];
      for ( User test : users){
      if(getCurrentObject != null && !getCurrentObject .isEmpty()) {
if(getCurrentObject[0].Queue_Members__c == null)
   getCurrentObject[0].Queue_Members__c = '';
getCurrentObject[0].Queue_Members__c = getCurrentObject[0].Queue_Members__c + ' ' + test.name;
}

getCurrentObject[0].Next_Queue_Reassignment_User__c =+ users.get(1).name;
getCurrentObject[0].Last_Queue_Reassignment_User__c =+ users.get(0).name;


update getcurrentobject[0];


}   
      }
   }
}

I am trying to make a test class for the  same , Here are the steps I am doing for testing 

1. Creating 4 test users

2.Adding those users in a test queue

3. Updating my fields on my  Custom object with User name and Queue ID 

Not sure if its the right approach 

Here is my test Class - 

@isTest
private class lookUpAccountAnnotation_Test{
   @TestSetup
     static void setup() {    
    // Setup 4 Test Users
 Group grpObj = new Group(Type='Queue', Name='Test Queue1');
insert grpObj;
QueueSObject qObj = new QueueSObject(SobjectType='Lead', QueueId=grpObj.Id);
insert qObj;
    Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
    List<User> users = new List<User>();

    while (users.size() < 5) {
      Blob b = Crypto.GenerateAESKey(128);
      String h = EncodingUtil.ConvertTohex(b);
      String uid = h.SubString(0,8);
      //insert 4 test users
      User u = new User(Alias = uid, Email= uid + '@myorg.com', 
          EmailEncodingKey='UTF-8',LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', ProfileId = p.Id, 
          TimeZoneSidKey='America/New_York', UserName= uid + '@myorg.com');      
         ID gr = [SELECT Id FROM Group WHERE Name = 'Test Queue1'].Id;
         ID us = [SELECT Id , Name FROM User WHERE LastName='Testing'].Id;
         //Add one user in a test queuecreated above
        GroupMember gm = new GroupMember(GroupId = gr, UserOrGroupId = us);
           insert gm;
    }
System.Test.startTest();

QueueDistroHelper__c q = new QueueDistroHelper__c();
insert q;
//insert user name and Queue ID  in custom Object  
q.Related_Queue_Id__c = grpObj.Id;
q.Queue_Members__c = users.get(1).Name;
lookUpAccountAnnotation l = new lookUpAccountAnnotation();
//queryHelper q = new QueueDistroHelper__c(Name='TestQuery' , Queue_Members__c=users.name);    

System.Test.stopTest();

}
}
I have made an @invocableMethod , And I grab some values like Queue ID and Record ID form my Custom Object (QueueDistroHelper__c) . 
All I want to do is Get all users who are in  the Queue (I grab the queue ID from custom field on the Custom object) . And then show all that users on  a field called Queue_Members__c on same Custom object . 
I am not able to add the results to custom field 
Here is my code 
 
global class lookUpAccountAnnotation {
public class inputValues{
        @InvocableVariable(label='Queue ID' required=true)
        public string QueueId;
        @InvocableVariable(label='Record Id' required=true)
        public Id recordid;
       
    }
   @InvocableMethod
    public static void deletePackageLicense(List<inputValues> inputs){
    
      for (inputValues i : inputs)
   {
      List<QueueDistroHelper__c> getcurrentobject =  [SELECT Queue_Members__c FROM QueueDistroHelper__c WHERE Id=:i.recordid  LIMIT 1];
      List<User> users =  [SELECT
                    id,name
                FROM
                    user
                WHERE
                    id IN ( SELECT userOrGroupId FROM groupmember WHERE groupId = :i.QueueID )
                    AND
                    isActive = true
                ORDER BY
                    firstName];
      for (User test : users ){
     //Add User.name in Queue_Members__c
      }
      }
   }
}

So all I want to do is add the test.name to  Queue_Members__c

So I have an apex class that does 6 queries , one on event and rest on leads. 

I call the results of the query on a visual force page. 

Everything is working perfect. The only problem is, I do not know how to create a test class for this. 

Here is my apex Class that does the query  

public with sharing class TestDisplayQueryList{
public List<Event> getEvents {get; set;}
public List<Lead> getLeads {get; set;}
public List<Lead> getlast7Leads{get; set;}
public List<Lead> getlast15Leads{get; set;}
public List<Lead> getlast30Leads{get; set;}
public TestDisplayQueryList(){

//get all future  Events

getEvents = [SELECT StartDateTime,Subject,WhoId FROM Event WHERE OwnerId = :UserInfo.getUserId() AND StartDateTime = TODAY ];

//Get leads Created withing one day

getLeads = [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:1  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

//Get leads created within 7 days

getlast7Leads = [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:7  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

//Get leads created witing 15 days

getlast15leads= [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:15  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

//Get leads Created within 30 days

getlast30leads=[SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:30  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

}
}


I made few test classes that insert some leads and events , But was not able to go further than that. 

What could be the better approach for the test class for this. 

How do I define a Date field  in the class to call in a Constructor

Here is my  class - 

public class CustomFields {
            public String fieldName;
            public String stringValue;
           
            public CustomFields(String fieldName, String stringValue){
                this.fieldName = fieldName;
                this.stringValue = stringValue;
            }
 

Here is the constructor 

jo.customFields = new List<CustomFields>();
            jo.customFields.add(new CustomFields('CX.LEADS360ID', currentOpp.Opportunity_ID__c));
            jo.customFields.add(new CustomFields('CX.LEADS360CAMPAIGN', currentOpp.Lead_Source_Name__r.Name));
            jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', currentOpp.Legacy_Lead_Date_Added__c));
            jo.customFields.add(new CustomFields('CX.CRM.OWNER.EMAIL', currentOpp.Owner.Email));
 

I cannot add 

jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', currentOpp.Legacy_Lead_Date_Added__c));

Because Opp.Legacy_Lead_Date_Added__c is a date field . How do I add a date variable in my class and call it in the constructor
       

Error I am getting 

Constructor not defined: [CustomFields].<Constructor>(String, Date) 

How do I Write a SOQL query which selects all leads that are modified within 60 minutes from now 

Select all  the lead Lastmodified date within 60 minutes or last hour 

I have a field called Branch__c which is a picklist . I want to make that field required ONLY when I edit the lead, Not when I creat a  new lead. So basically first time when lead is created make is not rewuired, next time lead is edited and saved, makeit required! 

Any suggestions ?

I want to add a field on the user profile called "Today's lead Count" and then count the number of leads assigned to him on that day. Like today. 

Is there a way I can do this  using process builer or workflow!

I have a Process builder that Adds the Email of the Account that is related to the opportunity in the Oppotunity object. I have made Account Phone field on Opportunity for that. 

User-added image

 User-added image

I am Getting Errors as - 

The flow failed to access the value for myVariable_current.Account.PersonEmail because it hasn't been set or assigned.

I have added a List button on campaign members that execicutes a javascript and deletes all campaign members in the campaign 

I am Getting error-  

{faultcode:soapenv:Client,Falultstrinf:Unexpected Element

{urn:partner.soap.sforce.com} type during simple type deserializition'}

 

Here is my Code 

{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}

var result = sforce.connection.query("select Id from CampaignMember where Campaign.Name = '{!Campaign.Name}' ");
var records = result.getArray("records");


 var opt = confirm("Are you sure you want to delete selected records ?");
    if (opt == true) {
        var errors = [];
        var delresult = sforce.connection.deleteIds(records);
        if (result && result.length) {
            var numFailed = 0;
            var numSucceeded = 0;
            for (var i = 0; i < result.length; i++) {                 var res = result[i];                 if (res && res.success == 'true') {                     numSucceeded++;                 } else {                     var es = res.getArray("errors");                     if (es.length > 0) {
                        errors.push(es[0].message);
                    }
                    numFailed++;
                }
            }
            if (numFailed > 0) {
                alert("Failed: " + numFailed + "nSucceeded: " + numSucceeded + " n Due to: " + errors.join("n"));
            } else {
                alert("Number of records deleted: " + numSucceeded);
            }
        }
        window.location.reload();
    }

I have an apex class that gets the Leads from the Query in the metadada and does some basic updates on leads and adds them in campaign 

The class is working fine, But I wanter to make is Batchable in case I get more than 100 records. 

Here is my apex class  - 

public with sharing class leadtester implements Schedulable   { 
 public list<Lead>  quo{get;set;}

public void execute(SchedulableContext ctx){ 
     Leads__mdt [] leadVals = [SELECT Final_Query__c FROM Leads__mdt ];
     
     
     list<Leads__mdt> u = [SELECT 
 Retention_Updated_Queue__c,Add_to_Campaign__c FROM Leads__mdt  ]; 
        
     quo= Database.query(leadVals[0].Final_Query__c );

        for(Lead ldt :quo){
      if(ldt != null ) {
       //Update those leads with new owner ID
       string test  = ldt.OwnerId;
       list<Group> v = [Select name from Group where ID  =:test]; 
       ldt.Previous_Lead_Owner__c = v[0].name;
       ldt.Lead_Status_at_Last_Retention__c = ldt.Status;
       ldt.OwnerId = u[0].Retention_Updated_Queue__c;
       ldt.Last_Retention_Date__c = Datetime.now(); 
       ldt.Retention_Count__c = ldt.Retention_Count__c +1 ; 
        if(u[0].Add_to_Campaign__c !=Null){  
       CampaignMember mem = new CampaignMember (campaignid=u[0].Add_to_Campaign__c, leadid=ldt.id);
        
        database.insert (mem, false);
        }
        }
        update quo;
        }
        }
        
}

I am doing a SOQL query and then updating records. The trick here is . I am grabbing my query from two custom fields which are in the Custom Settings . My code works fine records are getting queried and updated. I am having big trouble in making test class for this . Help is appriciated . Here is my Apex Class -

public with sharing class textInputsConsecond implements Schedulable   { 
 public list<Lead>  quo{get;set;}


 public void execute(SchedulableContext ctx){ 
   quo= Database.query(Lead__c.getInstance().Database_Query__c + 
   Lead__c.getInstance().Database_Query2__c);
   for(Lead ldt :quo){
   //Update those leads with new owner ID
   ldt.OwnerId = '00G3B000001hp6VUAQ';

    }

   update quo;
 }
 }


Here is the screenshot of my Query in the Field in custom settings -

User-added image

So my query is basically Database Query field + Database Query2 Field

The only reason to use two fields is salesforce is not allowing text box more that 255 characters  

I have made an @invocableMethod , And I grab some values like Queue ID and Record ID form my Custom Object (QueueDistroHelper__c) . 
All I want to do is Get all users who are in  the Queue (I grab the queue ID from custom field on the Custom object) . And then show all that users on  a field called Queue_Members__c on same Custom object . 
I am not able to add the results to custom field 
Here is my code 
 
global class lookUpAccountAnnotation {
public class inputValues{
        @InvocableVariable(label='Queue ID' required=true)
        public string QueueId;
        @InvocableVariable(label='Record Id' required=true)
        public Id recordid;
       
    }
   @InvocableMethod
    public static void deletePackageLicense(List<inputValues> inputs){
    
      for (inputValues i : inputs)
   {
      List<QueueDistroHelper__c> getcurrentobject =  [SELECT Queue_Members__c FROM QueueDistroHelper__c WHERE Id=:i.recordid  LIMIT 1];
      List<User> users =  [SELECT
                    id,name
                FROM
                    user
                WHERE
                    id IN ( SELECT userOrGroupId FROM groupmember WHERE groupId = :i.QueueID )
                    AND
                    isActive = true
                ORDER BY
                    firstName];
      for (User test : users ){
     //Add User.name in Queue_Members__c
      }
      }
   }
}

So all I want to do is add the test.name to  Queue_Members__c

So I have an apex class that does 6 queries , one on event and rest on leads. 

I call the results of the query on a visual force page. 

Everything is working perfect. The only problem is, I do not know how to create a test class for this. 

Here is my apex Class that does the query  

public with sharing class TestDisplayQueryList{
public List<Event> getEvents {get; set;}
public List<Lead> getLeads {get; set;}
public List<Lead> getlast7Leads{get; set;}
public List<Lead> getlast15Leads{get; set;}
public List<Lead> getlast30Leads{get; set;}
public TestDisplayQueryList(){

//get all future  Events

getEvents = [SELECT StartDateTime,Subject,WhoId FROM Event WHERE OwnerId = :UserInfo.getUserId() AND StartDateTime = TODAY ];

//Get leads Created withing one day

getLeads = [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:1  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

//Get leads created within 7 days

getlast7Leads = [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:7  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

//Get leads created witing 15 days

getlast15leads= [SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:15  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

//Get leads Created within 30 days

getlast30leads=[SELECT Id,Name,Status,Phone,Email FROM Lead WHERE CreatedDate = LAST_N_DAYS:30  AND (Status ='New' or Status = 'Assigned' or Status = 'Working') AND OwnerId = :UserInfo.getUserId() LIMIT 5];

}
}


I made few test classes that insert some leads and events , But was not able to go further than that. 

What could be the better approach for the test class for this. 

How do I define a Date field  in the class to call in a Constructor

Here is my  class - 

public class CustomFields {
            public String fieldName;
            public String stringValue;
           
            public CustomFields(String fieldName, String stringValue){
                this.fieldName = fieldName;
                this.stringValue = stringValue;
            }
 

Here is the constructor 

jo.customFields = new List<CustomFields>();
            jo.customFields.add(new CustomFields('CX.LEADS360ID', currentOpp.Opportunity_ID__c));
            jo.customFields.add(new CustomFields('CX.LEADS360CAMPAIGN', currentOpp.Lead_Source_Name__r.Name));
            jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', currentOpp.Legacy_Lead_Date_Added__c));
            jo.customFields.add(new CustomFields('CX.CRM.OWNER.EMAIL', currentOpp.Owner.Email));
 

I cannot add 

jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', currentOpp.Legacy_Lead_Date_Added__c));

Because Opp.Legacy_Lead_Date_Added__c is a date field . How do I add a date variable in my class and call it in the constructor
       

Error I am getting 

Constructor not defined: [CustomFields].<Constructor>(String, Date) 

I have a Process builder that Adds the Email of the Account that is related to the opportunity in the Oppotunity object. I have made Account Phone field on Opportunity for that. 

User-added image

 User-added image

I am Getting Errors as - 

The flow failed to access the value for myVariable_current.Account.PersonEmail because it hasn't been set or assigned.

Hi All, 

I need to remove all campaign members from within an apex class (unmanaged package), I can get get campaign ID, but I can't find what is the method to remove all members, can someone point me in the right direction?

Thanks!

-Dave
  • August 16, 2016
  • Like
  • 0