• The new Learner
  • NEWBIE
  • 140 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 60
    Questions
  • 92
    Replies
Hi Experts,
 
I have written a trigger, when the opportunity contain inactive product I need to throw an error, however, its working fine for one product, when it have more than one , when I am trying to delete it's not working its throwing an error by saying  "select correct product"
can anyone help me out? 
 
public static void products(Set<Id> oppIds, List<Opportunity> opplist)
    {
        
        List<OpportunityLineItem> opplineitems = [SELECT OpportunityId FROM OpportunityLineItem WHERE Product2.IsActive = false AND OpportunityId IN: OppIds];
        
        Set<Id> opptyId = New Set<Id>();
        for(OpportunityLineItem opplt:opplineitems)
        {
            
            opptyId.add(opplt.OpportunityId);
        }
        
        for (Opportunity opp :opplist) 
        {
            
            if(opptyId.contains(opp.Id))
            {
                
                opp.addError('select correct product');

            }
        }
            
    }

 
Hi Experts,

I want to post a chatter on the event record on a daily basis when the event status-completed and When the Event Date is passed. Chatter should not update the same record in their next batch . Kindly help me out.
Hi Experts,

Can anyone help me out, how to achieve the below functionality using a trigger.

Need to link all contacts from the related account that are flagged as key contacts to an opportunity on that account when it is created.
Thanks in advance.
Hi Experts,

I have requirment i need to update account field  product_value__c with the  product  field Family__c( all the product values has to add to product value field),when ever the opprotunity stage is closed. to achieve this i have written batch class on opportunity but its not working as expected. Its taking lot of time to update records.
 
global class batchAccountUpdate implements Database.Batchable<sObject> {
    
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        
        String query = 'SELECT id,Accountid,stagename,IsRenewal__c FROM Opportunity ';
        
        return Database.getQueryLocator(query);
        
    }
    

    
    global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
        
        set<id>accountids= new set<id>();
        set<id>opptyids= new set<id>();
        set<Id> addOn = new set<Id>();
        list<account>accountupdate= new list<account>();
        map<id,account> accmap = new map<id,account>();
        Map<id,OpportunityLineItem > accountid=new map<id,OpportunityLineItem >();  
         Map<id,Product2 > products=new map<id,Product2 >();
        for(Opportunity o : scope)
        {
            if(o.stagename=='closed')
            {
              
                opptyids.add(o.id);
            }  
            
        }
        
        for(Product2 oli : [SELECT id,Business__c,Family__c FROM Product2 where Business__c = 'sales']) 
        {
            
            addOn.add(oli.Id);
            products.put(oli.id,oli);
             
        }
        
        Map<Id,OpportunityLineItem > oppsToget = new Map<Id,OpportunityLineItem >([SELECT id,Product_Lookup__r.Business__c,Product_Lookup__r.Family__c,OpportunityId,Product_Lookup__c,opportunity.accountid,opportunity.StageName FROM OpportunityLineItem where Product_Lookup__c IN:products.keyset() and opportunityid in:opptyids]);
       
        for (OpportunityLineItem oli3: oppsToget.values())
        {
            accountid.put(oli3.opportunity.accountid,oli3);
           
            
        } 
        
        Map<Id,Account> mapAccount = new Map<Id,Account> ([select id,product_value__c from account where id in :accountid.keyset()]);    
        for(account a:mapAccount.values())
        {
            if(accountid.containskey(a.id))
            {
                system.debug('@@accountid.containskey(a.id)'+accountid.containskey(a.id)); 
                for(OpportunityLineItem line: accountid.values())
                {
                    if(line.Product_Lookup__c!= null)
                    {
                     
                           String prodstring='';
                           set<string>unique=new set<String>();  
                           for(String s:line.Product_Lookup__r.Family__c.split(','))
                           {
                           unique.add(s);
                            system.debug('@@unique'+unique);  
                           }
                            if(unique.size()!=0){
                        for(String st : unique ){  
                            prodstring = prodstring +','+ st;
                              system.debug('@@prodstring '+prodstring );
                            }
                         }
                        a.product_value__c = prodstring;
                      
                        accountupdate.add(a);
                      
                        
                       
                    }  
                }
            }
        }
        accmap.putall(accountupdate);

        if(!accmap.isEmpty()){
            Database.SaveResult[] IsShareResult = Database.update(accmap.values(), false);
            
        }
    }   
    
 
    
    global void finish(Database.BatchableContext BC) {
        
    }
    
}

 
HI Experts,

Can anyone help me out, how can i send an email to public group users under a queue based on language. Thanks in advance
HI Experts,

I want to send an email to queue members when ever the lead is created. when new lead is created its assigining to queue. now i want to send an email for queue users can anyone help me. thanks in advance
HI Experts,

I have written a visual force component and an apex class, problem over here is that, i can able to cover upto 73%, and not able to cover soql queries , lines which i bolded those are the lines which i am not able to cover. can anyone help me  please below is my code.
 
public with sharing class CampaignApprovalReject {
    
    
  public String camIds {get;set;}
    public Campaign camp{get;set;}
    Public ProcessInstanceStep pStep{get;set;}
    Public String sfdcBaseURL{get;set;}
    
    
    public CampaignApprovalReject (){
        
    }
    public ProcessInstanceStep getApprovalSteps() {
       
        if (camIds != null) 
        {
           
            pStep = [Select SystemModstamp,StepStatus, ProcessInstanceId, OriginalActorId,OriginalActor.Name,
                     Comments, ActorId From ProcessInstanceStep where ProcessInstance.TargetObjectId=:camIds order by SystemModstamp desc limit 1];  
            system.debug('@@@pStep'+pStep); 
        }
        return pStep ;
    }
    
    Public campaign getcampaigns(){
        if (camIds != null) 
        {
            camp= [Select id,name,Type,Description__c,ParentName__c from campaign where id=:camIds limit 1];
            
        }
        
        return camp;
    }
 
    
    public List<ProcessInstanceHistory> getrecallApprovalSteps() 
    {
        if (camIds != null) 
        {
            camp= [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from campaign where Id = :camIds ];
            return camp.ProcessSteps;
        }
        return new List<ProcessInstanceHistory>();
    }
    
    Public String getURL(){
        if (camIds != null) {
            sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+camp.id;
        }
        return sfdcBaseURL;
    }
    
}

Below is my test class.
 
@isTest
public class Campaign_Test {
    @isTest static void myTest() 
    {
        
        Campaign a = new Campaign ();
        a.Name='Example';
        a.Description__c='test';
        a.Status='Planned';
        a.StartDate=system.today();
        a.CurrencyIsoCode='USD';
        a.Parent__c=true;
        a.type='Nurture';
        insert a;
        Campaign a2=[Select id,name,Type,CAP_WT_Campaign_Short_Description__c from campaign where name='Example' LIMIT 1];
        System.assert(a2!=null);        
        Approval.ProcessSubmitRequest req1 =  new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(a.id);
        req1.setProcessDefinitionNameOrId('Example_Process');
        req1.setSkipEntryCriteria(true);
        CampaignApprovalReject cmp = new CampaignApprovalReject();
        ProcessInstanceStep  process = cmp.getApprovalSteps();
        Campaign itemObj = cmp.getcampaigns();
        list<ProcessInstanceHistory> PI=cmp.getrecallApprovalSteps();
        string itemob=cmp.getURL();
        cmp.camIds='Example';
        System.assertEquals('Example', a.Name);
        
    }
}

 
HI Experts,

I have requirment where i need to create VF email template, using custom labels for each section to allow for users receiving the template to see it in their own language.  Can anyone help me how to create it.
HI Experts,

I have requirment where i need to login attempts of a community user ,its more than 5 login attempts , i need to populate an error message. can anyone help me please.
I have to populate the image based on the below conditions.

1. when the record type is "sales" or "service" and Date__c is greater than (Today() -160) then it should be green.
2. when the record type is "sales" or "service" and Date__c is less than (Today() -160) then it should be red.
3. when the record type is "sales" or "service" or "marketing" and status is not equal "renewed" and date__c <today then it should be red.
4. when image__c field is is not blank then it should it should be grey.

can anyone help me please.
Hi Experts,

I want to display a logo from second page page onwards, in an visulforce page can anyone help me how to do that.(from second page onwards that image has to be there in every page )
HI Experts,

Can anyone help me out, how to create below table format using html or apex table.
User-added image
Hi Experts,

I am rendering a pdf and populating data for every single record i want to break and again i need to show in seprate table next record. can anyone let me know please how to do that.
Hi Experts,

I have requirment i need  download account related contact object records as pdf, i can able to make it as pdf, but , i want download once i click on that button,i am using this page as button source. can anyone help me.
 
<apex:page readOnly="true"     
           standardController="Account"    
           applyHtmlTag="false"     
           sidebar="false"     
           showHeader="false"     
           cache="true"     
           renderAs="advanced_pdf">    
        
    <head>    
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />    
        <style type="text/css">    
            
            @page {    
              
                size: A4 landscape;    
                border: 2px solid black;    
                padding-left: 8px;    
                padding-right: 8px;      
                  
            }    
                
            th {    
              
                text-align: center;    
                font-weight: bold;    
                  
            }    
                
                
            td {    
              
                text-align: center;    
                font-size: 14px;    
                  
            }    
                
        </style>    
          
    </head>    
      
    <center>    
      
        <h3>Testing Advanced PDF = {!Account.Name}</h3>    
          
    </center><br/><br/>    
      
    <table border="1" width="99%">    
      
        <tr>    
          
            <th>First Name</th>    
            <th>Last Name</th>    
              
        </tr>    
        <apex:repeat value="{!Account.Contacts}" var="con">    
          
            <tr>    
              
                <td>{!con.FirstName}</td>    
                <td>{!con.LastName}</td>    
                  
            </tr>    
              
        </apex:repeat>    
          
    </table>    
    
</apex:page>

 
Hi Experts,

Can anyone let me know how to cast sobject to a specific object vice versa please. below i am getting the records, now i want to cast that object to specifi object.
SObjectType objectType = records.getSObjectType();
HI Experts,

i am trying to get the difference between two dates using business hours difference method like below to exclude holidays and weeknds while converting milliseconds in to date i am not getting anything can anyone help please.
 
here is method


 long temp= BusinessHours.diff(
                            ri.Completion_Date__c,
                            ri.Completion_Date__c-3,
                            businessHoursId);

output: DEBUG|temp-1020 

DateTime gmtDatetime = DateTime.newInstance(temp);

output: gmtDatetime1969-12-31 23:59:58

 
HI Experts,

I Have requirment ,where i need to find out the businessday between two days, eg: if startdate is today, and startday-3, i need to find out the businessday between these two days by excluding holidays and weekends.
Hi Experts, 

I want to find out the business day between two dates need to exclude holidays and weekends. Can anyone help me pls 
Hi Experts,

I am getting below error for the case comment. can anyone help me please. Error: SObject type CaseComment is not supported by this unit of work. 
below is the code. can anyone help me how to fix this issue.

 
public void registerNew(SObject record, Schema.sObjectField relatedToParentField, SObject relatedToParentRecord)
    {
        if(record.Id != null)
            throw new UnitOfWorkException('Only new records can be registered as new');
        String sObjectType = record.getSObjectType().getDescribe().getName();
        if(!m_newListByType.containsKey(sObjectType))
            throw new UnitOfWorkException(String.format('SObject type {0} is not supported by this unit of work', new String[] { sObjectType }));
        m_newListByType.get(sObjectType).add(record);
        if(relatedToParentRecord!=null && relatedToParentField!=null)
            registerRelationship(record, relatedToParentField, relatedToParentRecord);
    }

 
Hi Experts,

There is an email is comes from webservice, in that email we are searching for the policy number with that policy number we are creating case but problem here is that its  reading phone number also and creating case, so i observerd that phone number is coming prefix as "tel,T,telephone,phone,fax,F,+27" if i find anythig like this i need to ignore.
below is the expression we are using. can anyone help me please

public static final String REGEX_PATTERN_POLICY_NUMBER = '[0-9]{6,12}';
Hi Experts,

Can anyone help me how to write test class for the below method.

public override void onCommit(){
        
        OM_ManageService manageRemittanceSVC = (OM_ManageRService)this.svc;
        String accJSON = OM_WorkService.getJSONAttribute(manageRemittanceSVC.jsonString, 'AccountInfo');
        Map<String, List<SObject>> accObjects =  OM_WorkService.getSObjects(accJSON);
        Account acc = (Account)accObjects.get('Account')[0];
        
        if(acc!= null){
            upsert acc;
            super.onCommit();
            
            }
            
        Below is the OM_WorkService.getJSONAttribut    
             
             public static String getJSONAttribute(String jsonStr, String attr){
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonStr);
        if(m.containsKey(attr))
            return (String)m.get(attr);
        
        return null;
    }
 
Hi Experts,
 
I have written a trigger, when the opportunity contain inactive product I need to throw an error, however, its working fine for one product, when it have more than one , when I am trying to delete it's not working its throwing an error by saying  "select correct product"
can anyone help me out? 
 
public static void products(Set<Id> oppIds, List<Opportunity> opplist)
    {
        
        List<OpportunityLineItem> opplineitems = [SELECT OpportunityId FROM OpportunityLineItem WHERE Product2.IsActive = false AND OpportunityId IN: OppIds];
        
        Set<Id> opptyId = New Set<Id>();
        for(OpportunityLineItem opplt:opplineitems)
        {
            
            opptyId.add(opplt.OpportunityId);
        }
        
        for (Opportunity opp :opplist) 
        {
            
            if(opptyId.contains(opp.Id))
            {
                
                opp.addError('select correct product');

            }
        }
            
    }

 
Hi Experts,

I want to post a chatter on the event record on a daily basis when the event status-completed and When the Event Date is passed. Chatter should not update the same record in their next batch . Kindly help me out.
Hi Experts,

Can anyone help me out, how to achieve the below functionality using a trigger.

Need to link all contacts from the related account that are flagged as key contacts to an opportunity on that account when it is created.
Thanks in advance.
Hi Experts,

I have requirment i need to update account field  product_value__c with the  product  field Family__c( all the product values has to add to product value field),when ever the opprotunity stage is closed. to achieve this i have written batch class on opportunity but its not working as expected. Its taking lot of time to update records.
 
global class batchAccountUpdate implements Database.Batchable<sObject> {
    
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        
        String query = 'SELECT id,Accountid,stagename,IsRenewal__c FROM Opportunity ';
        
        return Database.getQueryLocator(query);
        
    }
    

    
    global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
        
        set<id>accountids= new set<id>();
        set<id>opptyids= new set<id>();
        set<Id> addOn = new set<Id>();
        list<account>accountupdate= new list<account>();
        map<id,account> accmap = new map<id,account>();
        Map<id,OpportunityLineItem > accountid=new map<id,OpportunityLineItem >();  
         Map<id,Product2 > products=new map<id,Product2 >();
        for(Opportunity o : scope)
        {
            if(o.stagename=='closed')
            {
              
                opptyids.add(o.id);
            }  
            
        }
        
        for(Product2 oli : [SELECT id,Business__c,Family__c FROM Product2 where Business__c = 'sales']) 
        {
            
            addOn.add(oli.Id);
            products.put(oli.id,oli);
             
        }
        
        Map<Id,OpportunityLineItem > oppsToget = new Map<Id,OpportunityLineItem >([SELECT id,Product_Lookup__r.Business__c,Product_Lookup__r.Family__c,OpportunityId,Product_Lookup__c,opportunity.accountid,opportunity.StageName FROM OpportunityLineItem where Product_Lookup__c IN:products.keyset() and opportunityid in:opptyids]);
       
        for (OpportunityLineItem oli3: oppsToget.values())
        {
            accountid.put(oli3.opportunity.accountid,oli3);
           
            
        } 
        
        Map<Id,Account> mapAccount = new Map<Id,Account> ([select id,product_value__c from account where id in :accountid.keyset()]);    
        for(account a:mapAccount.values())
        {
            if(accountid.containskey(a.id))
            {
                system.debug('@@accountid.containskey(a.id)'+accountid.containskey(a.id)); 
                for(OpportunityLineItem line: accountid.values())
                {
                    if(line.Product_Lookup__c!= null)
                    {
                     
                           String prodstring='';
                           set<string>unique=new set<String>();  
                           for(String s:line.Product_Lookup__r.Family__c.split(','))
                           {
                           unique.add(s);
                            system.debug('@@unique'+unique);  
                           }
                            if(unique.size()!=0){
                        for(String st : unique ){  
                            prodstring = prodstring +','+ st;
                              system.debug('@@prodstring '+prodstring );
                            }
                         }
                        a.product_value__c = prodstring;
                      
                        accountupdate.add(a);
                      
                        
                       
                    }  
                }
            }
        }
        accmap.putall(accountupdate);

        if(!accmap.isEmpty()){
            Database.SaveResult[] IsShareResult = Database.update(accmap.values(), false);
            
        }
    }   
    
 
    
    global void finish(Database.BatchableContext BC) {
        
    }
    
}

 
HI Experts,

Can anyone help me out, how can i send an email to public group users under a queue based on language. Thanks in advance
HI Experts,

I want to send an email to queue members when ever the lead is created. when new lead is created its assigining to queue. now i want to send an email for queue users can anyone help me. thanks in advance
HI Experts,

I have written a visual force component and an apex class, problem over here is that, i can able to cover upto 73%, and not able to cover soql queries , lines which i bolded those are the lines which i am not able to cover. can anyone help me  please below is my code.
 
public with sharing class CampaignApprovalReject {
    
    
  public String camIds {get;set;}
    public Campaign camp{get;set;}
    Public ProcessInstanceStep pStep{get;set;}
    Public String sfdcBaseURL{get;set;}
    
    
    public CampaignApprovalReject (){
        
    }
    public ProcessInstanceStep getApprovalSteps() {
       
        if (camIds != null) 
        {
           
            pStep = [Select SystemModstamp,StepStatus, ProcessInstanceId, OriginalActorId,OriginalActor.Name,
                     Comments, ActorId From ProcessInstanceStep where ProcessInstance.TargetObjectId=:camIds order by SystemModstamp desc limit 1];  
            system.debug('@@@pStep'+pStep); 
        }
        return pStep ;
    }
    
    Public campaign getcampaigns(){
        if (camIds != null) 
        {
            camp= [Select id,name,Type,Description__c,ParentName__c from campaign where id=:camIds limit 1];
            
        }
        
        return camp;
    }
 
    
    public List<ProcessInstanceHistory> getrecallApprovalSteps() 
    {
        if (camIds != null) 
        {
            camp= [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from campaign where Id = :camIds ];
            return camp.ProcessSteps;
        }
        return new List<ProcessInstanceHistory>();
    }
    
    Public String getURL(){
        if (camIds != null) {
            sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+camp.id;
        }
        return sfdcBaseURL;
    }
    
}

Below is my test class.
 
@isTest
public class Campaign_Test {
    @isTest static void myTest() 
    {
        
        Campaign a = new Campaign ();
        a.Name='Example';
        a.Description__c='test';
        a.Status='Planned';
        a.StartDate=system.today();
        a.CurrencyIsoCode='USD';
        a.Parent__c=true;
        a.type='Nurture';
        insert a;
        Campaign a2=[Select id,name,Type,CAP_WT_Campaign_Short_Description__c from campaign where name='Example' LIMIT 1];
        System.assert(a2!=null);        
        Approval.ProcessSubmitRequest req1 =  new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(a.id);
        req1.setProcessDefinitionNameOrId('Example_Process');
        req1.setSkipEntryCriteria(true);
        CampaignApprovalReject cmp = new CampaignApprovalReject();
        ProcessInstanceStep  process = cmp.getApprovalSteps();
        Campaign itemObj = cmp.getcampaigns();
        list<ProcessInstanceHistory> PI=cmp.getrecallApprovalSteps();
        string itemob=cmp.getURL();
        cmp.camIds='Example';
        System.assertEquals('Example', a.Name);
        
    }
}

 
I have to populate the image based on the below conditions.

1. when the record type is "sales" or "service" and Date__c is greater than (Today() -160) then it should be green.
2. when the record type is "sales" or "service" and Date__c is less than (Today() -160) then it should be red.
3. when the record type is "sales" or "service" or "marketing" and status is not equal "renewed" and date__c <today then it should be red.
4. when image__c field is is not blank then it should it should be grey.

can anyone help me please.
Hi Experts,

I want to display a logo from second page page onwards, in an visulforce page can anyone help me how to do that.(from second page onwards that image has to be there in every page )
Hi Experts,

I am rendering a pdf and populating data for every single record i want to break and again i need to show in seprate table next record. can anyone let me know please how to do that.
Hi Experts,

I have requirment i need  download account related contact object records as pdf, i can able to make it as pdf, but , i want download once i click on that button,i am using this page as button source. can anyone help me.
 
<apex:page readOnly="true"     
           standardController="Account"    
           applyHtmlTag="false"     
           sidebar="false"     
           showHeader="false"     
           cache="true"     
           renderAs="advanced_pdf">    
        
    <head>    
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />    
        <style type="text/css">    
            
            @page {    
              
                size: A4 landscape;    
                border: 2px solid black;    
                padding-left: 8px;    
                padding-right: 8px;      
                  
            }    
                
            th {    
              
                text-align: center;    
                font-weight: bold;    
                  
            }    
                
                
            td {    
              
                text-align: center;    
                font-size: 14px;    
                  
            }    
                
        </style>    
          
    </head>    
      
    <center>    
      
        <h3>Testing Advanced PDF = {!Account.Name}</h3>    
          
    </center><br/><br/>    
      
    <table border="1" width="99%">    
      
        <tr>    
          
            <th>First Name</th>    
            <th>Last Name</th>    
              
        </tr>    
        <apex:repeat value="{!Account.Contacts}" var="con">    
          
            <tr>    
              
                <td>{!con.FirstName}</td>    
                <td>{!con.LastName}</td>    
                  
            </tr>    
              
        </apex:repeat>    
          
    </table>    
    
</apex:page>

 
HI Experts,

I Have requirment ,where i need to find out the businessday between two days, eg: if startdate is today, and startday-3, i need to find out the businessday between these two days by excluding holidays and weekends.
Hi Experts, 

I want to find out the business day between two dates need to exclude holidays and weekends. Can anyone help me pls