• @DEVS
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 7
    Replies
Why does this RegEx pattern not working in Salesforce ?

pattern myPattern = pattern.compile('@(microsoft|ms|microsoftsurface|msstore).com');
System.debug(myPattern.matcher('aba@ms.com').matches());

I tested it in https://regexr.com/ and it works !
  • December 06, 2019
  • Like
  • 0
How to create an Opportunity using Rest API with a particular Record type - when the user has access to multiple Record Types.

Below is the sample to create opportunity:
URI: services/data/v39.0/sobjects/Opportunity
Http Method: Post
Input: {"Name":"Opp1","CloseDate":"2018-08-01","StageName":"New","Probability":"10","Amount":"2000"}
  • July 04, 2017
  • Like
  • 0
I have a requirement to send weekly reports in email to indivudual memebrs as per their visibility.

I've an idea to write an apex class which I can schedule it using Scheduled Apex.
Inside the class I want to use ReportManager class to run a specific report.

My question here is - How can I run it as a specific user ? 
  • June 21, 2017
  • Like
  • 1
I have a requirement to send weekly reports in email to indivudual memebrs as per their visibility.

I've an idea to write an apex class which I can schedule it using Scheduled Apex.
Inside the class I want to use ReportManager class to run a specific report.

My question here is - How can I run it as a specific user ? 
  • June 21, 2017
  • Like
  • 1
I am experiencing DML Error 10001 ,

can you spot on which is needed to be optimize more in here.


public with sharing class UpdateStatus {
    public static final String ClsName  = 'UpdateStatus';
    public static boolean isExecuting=false;
    public static boolean isInvoked = false;
    public static boolean isCnclGSChkd = false;
    public static final String UpdateActiveStatus  = 'ActiveStatus' ;
    public static final String UpdateCancelStatus  = 'CancelStatus' ;
    public static final String UpdateRecType = 'RecTypeStat' ;
    public static final String UpdateCancelBff = 'CancelStats';
    public static final String  UpdateEndDate = 'UpdateEndDate';
    public static final string acctClient =Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account - Client').getRecordTypeId();
    public static final string acctClientInt =  Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account - InactiveClient').getRecordTypeId();
    public static final String  actv='Active';
    public static final String  cancl='Canceled';
    public static final String pendng =  'Pending';
    public static final String  accntCst= 'Account_Client';
    public static final String  cncled= 'Canceled';
    public static final String  inactv= 'Inactive';
    public static final Date enddateFuture = Date.newInstance(2100, 12, 31);
    public static  List<Id> cnclgmList = new List<Id>();
    public static final string profIntUser='Integration User';
    public static final string categNet='Verizon';
    

    public static void ActiveStatus(List<Group_Members> gmList)
    {

            Date EndDateFr;
            map<id,integer> prcOpn=new map<id,integer>();
            list<id> gpToProc=new list<id>();
            String profileName = [Select Name from Profile where Id = :UserInfo.getProfileId() limit 1].Name;
            for(Group_Members objGM : gmList){
                
                if(objGM.Status__c==pendng ){
                    gpToProc.add(objGM.Id);
                }
            }
            
            list<aggregateResult> PrcssLst=[select GM_ID,count(Id) OpenGM from WF_GM__c where GM_ID in:gpToProc 
                                              and (GA_Status__c='Closed') and GM_NS__c=null and GM_Sid__c !=null  group by GM_ID  limit 2000];
            for(aggregateResult agRst:PrcssLst)
            {
                prcOpn.put(string.valueof(agRst.get('GM_ID')),integer.valueof(agRst.get('OpenGM')));   
            }
            
            for(Group_Members objGM : gmList){
                if(objGM.EffDate__c<=system.today() && 
                   objGM.cancelDate__c==null){
                       EndDateFr = enddateFuture;
                   }
                else{
                    EndDateFr = objGM.cancelDate__c;
                }
                if(objGM.Status__c==pendng  && objGM.Network__c==categNet){
                    if(prcOpn.get(objGM.Id)>0)
                        objGM.Status__c=actv;
                }
                if(objGM.Status__c==pendng  && (objGM.Trans__c || objGM.Post__c)){
                    if(prcOpn.get(objGM.Id)>0)
                        objGM.Status__c=actv;
                }  
                if(profileName==profIntUser){
                    if(objGM.Status__c==cncled && EndDateFr>system.today() 
                       && objGM.EffDate__c<=system.today())
                    {
                        objGM.Status__c=actv;
                    }   
                }  
            }

    }

    public static void RecTypeStat(List<Group_Members> gmList)
    {
            set<id> accIds=new set<id>();
            Date gmEndDateFr;
            boolean isChnge=false;
            String profileName = [Select Name from Profile where Id = :UserInfo.getProfileId() limit 1].Name;
            Map<Id, Date> gmACCMap = new Map<Id, Date>();
            for(Group_Members objGM : gmList){
                gmACCMap.put(objGM.Account_c,objGM.EffDate__c);
                if(objGM.Status__c==actv && objGM.Network__c==categNet)
                {
                    accIds.add(objGM.Account_c);
                }
                if(objGM.Status__c==actv && (objGM.Trans__c || objGM.Post__c))
                {
                    accIds.add(objGM.Account_c);
                }
                
                if(profileName==profIntUser){
                    if(objGM.Status__c==cncled && gmEndDateFr>system.today() 
                       && objGM.EffDate__c<=system.today())
                    {
                        accIds.add(objGM.Account_c);
                    }
                }
                
            } 
            List<Account>  accLst =[Select id,RecordType.DeveloperName from Account WHERE ID IN :accIds Limit 50000] ;
            List<Account>  updtAccLst = New   List<Account>();
            
            if(!accIds.isEmpty()){
                for(Account objAcc : accLst){
                    if(objAcc.RecordType.DeveloperName != accntCst){
                        objAcc.RecordTypeId = acctClient;
                        objAcc.Account_Status__c=actv;
                        objAcc.CovCancelDate__c=null;
                        objAcc.EnrollDate__c = gmACCMap.get(objAcc.Id);
                        updtAccLst.add(objAcc);
                    }
                }
            }  
            
            if(!updtAccLst.isEmpty()){
                Database.update(updtAccLst);
            }
            isInvoked= true; 
        }
        
    }

    public static void CancelStats(List<Group_Members> grpmemList,map<id,Group_Members> grpmemListOld)
    {
            for(Group_Members grp:grpmemList)
            {
                boolean CnclChk=false;
                boolean CnclDteChk=false;
                if(grpmemListOld!=null)
                {
                    Group_Members grpOld=grpmemListOld.get(grp.Id);  
                    if(grp.cancelDate__c <> grpOld.cancelDate__c)
                        CnclChk=true;
                    if((grp.Status__c <> grpOld.Status__c) && grp.Status__c==cancl)
                    {
                        CnclDteChk=true;
                    }
                }
                else
                {
                    CnclChk=true;
                    if(grp.Status__c==cancl)
                    {
                        CnclDteChk=true; 
                    }
                }
                
                if(grp.cancelDate__c<=system.today() && CnclChk)
                {
                    grp.Status__c=cancl;
                    cnclgmList.add(grp.Id);
                    
                }
            }
            isCnclGSChkd = true;
        }
        
    }

    public static void CancelStatus(List<Group_Members> grpmemList,Map<ID,Group_Members> grpOldMap)
    {
            set<id> cnclAccIdsToPrcss=new set<id>();
            boolean isChnge=false;
            for(Group_Members grp:grpmemList)
            {
                if(grpOldMap !=null)
                {
                    Group_Members grpOld=grpOldMap.get(grp.Id);
                    if(grpOld.cancelDate__c !=grp.cancelDate__c  
                       || grpOld.Status__c !=grp.Status__c){
                           isChnge=true;     
                       }
                }
                
                else
                {
                    isChnge=true;
                }
                if(grp.cancelDate__c<=system.today() && isChnge)
                {
                    cnclAccIdsToPrcss.add(grp.Account_c);
                }
            }

            if(cnclAccIdsToPrcss.size() > 0){
                
                List<Account> accLst = [Select Id,Account_Status__c,RecordType.DeveloperName ,CovCancelDate__c,
                                        (select Status__c,cancelDate__c from Group_Member__r ORDER BY LastModifiedDate ASC)
                                        from Account where id in:cnclAccIdsToPrcss Limit 50000];
                List<Account>  acntIdsToPrcs = new List<Account>();
                List<Account>  finalacntIdsToPrcs = new List<Account>();
                Set<Id> processAccIds = New Set<Id>();
                boolean flag = false;
                Set<Id> accActv = New Set<Id> ();
                
                for(Account objAcc :accLst){
                    
                    if(!objAcc.Group_Member__r.isEmpty()){
                        for(Group_Members objGM : objAcc.Group_Member__r){
                            if(objGM.Status__c.equals(actv)){
                                flag = true;   
                                accActv.add(objAcc.id);
                                break;
                            }
                            else{
                                if(cnclgmList.contains(objGM.Id) && !processAccIds.contains(objAcc.id)  ){
                                    objAcc.CovCancelDate__c=objGM.cancelDate__c;
                                    objAcc.RecordTypeId =acctClientInt;
                                    objAcc.Account_Status__c=inactv;
                                    objAcc.EnrollDate__c=null;
                                    acntIdsToPrcs.add(objAcc); 
                                    processAccIds.add(objAcc.id);
                                }
                            }
                        }
                    }
                } 

                if(accActv.size() > 0){
                    processAccIds.removeAll(accActv);
                }

                for(Account accCus : acntIdsToPrcs){
                    if(processAccIds.contains(accCus.id)){
                        finalacntIdsToPrcs.add(accCus);
                    }
                }
                
                if(finalacntIdsToPrcs.size()>0 ){
                    
                    Database.update(acntIdsToPrcs);
                }
                
            }
            
            isExecuting=true;
      
    }
  
    public static void UpdateEndDate(List<Group_Members> grpmemList,map<id,Group_Members> grpmemListOld){
            List<id> gsIdLst = new List<id>();
            List<History__c> TCList = new List<History__c>(); 
            for(Group_Members grp:grpmemList)
            {
                if(grpmemListOld!=null)
                {
                    Group_Members grpOld=grpmemListOld.get(grp.Id);
                    
                    if(grp.History__c <> grpOld.History__c){
                        gsIdLst.add(grpOld.History__c);
                        
                    }
                } 
            }
            if(!gsIdLst.isEmpty()){
                for(History__c tp : [select id,EndDateTC__c,GA_TPB_Start_Date__c from History__c
                                                           where ID IN : gsIdLst Limit 50000]){
                                                               tp.EndDateTC__c = system.today()-1;
                                                               TCList.add(tp);                                                      
                                                           }
                Database.update(TCList);
            }
        }   
        
    }
}

 
Hello Reader

I  have a Custom object  (called API_Order__c) which has  lookup  field to Account
My plan is  to insert  MULTIPLE  records  in 1  REST API call and I am trying to build  the good JSON
I am not able to do this. I tried  the stanbdard REST  and I tried  to  use the COmposite/tree  REST

Seee below what I havew tried:

TEST 1

I want to  create  1 record  using REST command AND I want to reference the Account with External ID.
I use the below  REST
Method: POST
URL: /services/data/v39.0/sobjects/API_Order__c/

{
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"WDEF01663170"
         },
  "Account_Name__c" : "Adler-Apotheke",
  "NumberOfExpectedItemLines__c" : "2", 
  "External_Id__c" : "API_O_1003"
}

this is WORKING

​TEST 2
BUT  if I want to insert  MULTIPLE  records  I do not  know  what is  the right syntax


[
{
  "SourceFile__c" : "Value 1",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"XXXX"
         },
  "External_Id__c" : "API_O_1003"
},
{
  "SourceFile__c" : "Value 2",
  "Order_Date__c" : "2017-07-08",
  "Account__r" : 
         {
         "External_ID_vod__c":"YYYY"
         },
  "External_Id__c" : "API_O_1003"
}
]

I god  JSON parsng ERROR

TEST 3

I tried to use  the COMPOSITE  REST  call  to insert Multiple records and if I am passing the Salesforce ID  of  the  Account lookup is OK 

POST
/services/data/v39.0/composite/tree/API_Order__c

{
"records" :[
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref1"},
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__c" : "0015E000004jH2I"
  }, 
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref2"},
  "SourceFile__c" : "Val2",
  "Order_Date__c" : "2017-07-07",
  "Account__c" : "0015E000004jH2I"
   }]
}

TEST 4
BUT IF  I TRY  TO REFERENC ETHE ACCOUNT WITH EXTER NAL ID  I FAIL

POST
/services/data/v39.0/composite/tree/API_Order__c

{
"records" :[
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref1"},
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"WDEF01663170"
         },
  "Account_Name__c" : "Adler-Apotheke",
  "NumberOfExpectedItemLines__c" : "2", 
  "External_Id__c" : "API_O_1001"
  },
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref2"},
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"WDEF01663170"
         },
  "Account_Name__c" : "Adler-Apotheke",
  "NumberOfExpectedItemLines__c" : "2",
  "External_Id__c" : "API_O_1002"
   }]
}

I have the ERROR  message: Cannot reference a foreign key field Account__r.


Any help?  

Thanks in advance Csaba
How to create an Opportunity using Rest API with a particular Record type - when the user has access to multiple Record Types.

Below is the sample to create opportunity:
URI: services/data/v39.0/sobjects/Opportunity
Http Method: Post
Input: {"Name":"Opp1","CloseDate":"2018-08-01","StageName":"New","Probability":"10","Amount":"2000"}
  • July 04, 2017
  • Like
  • 0
I have a requirement to send weekly reports in email to indivudual memebrs as per their visibility.

I've an idea to write an apex class which I can schedule it using Scheduled Apex.
Inside the class I want to use ReportManager class to run a specific report.

My question here is - How can I run it as a specific user ? 
  • June 21, 2017
  • Like
  • 1
Hello Reader

I  have a Custom object  (called API_Order__c) which has  lookup  field to Account
My plan is  to insert  MULTIPLE  records  in 1  REST API call and I am trying to build  the good JSON
I am not able to do this. I tried  the stanbdard REST  and I tried  to  use the COmposite/tree  REST

Seee below what I havew tried:

TEST 1

I want to  create  1 record  using REST command AND I want to reference the Account with External ID.
I use the below  REST
Method: POST
URL: /services/data/v39.0/sobjects/API_Order__c/

{
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"WDEF01663170"
         },
  "Account_Name__c" : "Adler-Apotheke",
  "NumberOfExpectedItemLines__c" : "2", 
  "External_Id__c" : "API_O_1003"
}

this is WORKING

​TEST 2
BUT  if I want to insert  MULTIPLE  records  I do not  know  what is  the right syntax


[
{
  "SourceFile__c" : "Value 1",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"XXXX"
         },
  "External_Id__c" : "API_O_1003"
},
{
  "SourceFile__c" : "Value 2",
  "Order_Date__c" : "2017-07-08",
  "Account__r" : 
         {
         "External_ID_vod__c":"YYYY"
         },
  "External_Id__c" : "API_O_1003"
}
]

I god  JSON parsng ERROR

TEST 3

I tried to use  the COMPOSITE  REST  call  to insert Multiple records and if I am passing the Salesforce ID  of  the  Account lookup is OK 

POST
/services/data/v39.0/composite/tree/API_Order__c

{
"records" :[
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref1"},
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__c" : "0015E000004jH2I"
  }, 
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref2"},
  "SourceFile__c" : "Val2",
  "Order_Date__c" : "2017-07-07",
  "Account__c" : "0015E000004jH2I"
   }]
}

TEST 4
BUT IF  I TRY  TO REFERENC ETHE ACCOUNT WITH EXTER NAL ID  I FAIL

POST
/services/data/v39.0/composite/tree/API_Order__c

{
"records" :[
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref1"},
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"WDEF01663170"
         },
  "Account_Name__c" : "Adler-Apotheke",
  "NumberOfExpectedItemLines__c" : "2", 
  "External_Id__c" : "API_O_1001"
  },
  {
  "attributes" : {"type" : "API_Order__c", "referenceId" : "ref2"},
  "SourceFile__c" : "DE_1A_MSV3",
  "Order_Date__c" : "2017-07-07",
  "Account__r" : 
         {
         "External_ID_vod__c":"WDEF01663170"
         },
  "Account_Name__c" : "Adler-Apotheke",
  "NumberOfExpectedItemLines__c" : "2",
  "External_Id__c" : "API_O_1002"
   }]
}

I have the ERROR  message: Cannot reference a foreign key field Account__r.


Any help?  

Thanks in advance Csaba