• Raju yadav
  • NEWBIE
  • 65 Points
  • Member since 2017

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 24
    Replies
public class ContactpQueueable implements Queueable {
    public List<Contact> conToInsert = new List<Contact>();
    public List<Contact> conToDeleteList = new List<Contact>();
    
    
    public void execute(QueueableContext context) {
        if(!conToInsert.isEmpty()){
            Database.insert(conToInsert );
        }
        if(!conDeleteList.isEmpty()){
            Database.delete(conToDeleteList);
        }
    }
}
Hello All.
I have a class that looks for existing Leads with the same email address. 
If the email address exist add a task to the existing Lead.  This works.
The issue is that is still allows the creation of the duplicate Lead.  I do not want to throw an error message since the Leads may be imported via data loader.  If its creating a task because the email address already exist it should not be creating the lead.
Thanks,
M
trigger LeadPreventDuplicate on Lead (before insert,before update) {

    Map<String, Lead> leadMap = new Map<String, Lead>();
    for (Lead lead : System.Trigger.new) {
        
       //  Make sure we don't treat an email address that isn't changing during an update as a duplicate.  
    
        if ((lead.Email != null) && (System.Trigger.isInsert ||
                (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))) {
                leadMap.put(lead.Email, lead);
       }
    }
    
    List<task> addtask=New List<task>();
    for (Lead lead : [SELECT Email FROM Lead
                      WHERE 
                      Email IN :leadMap.KeySet()]) {
        Lead newLead = leadMap.get(lead.Email);
        
       // newLead.Email.addError('A lead with this email '
                        //       + 'address already exists.');
        addtask.add(new Task(
        WhoID =lead.id, 
        Status = 'Active',
        Subject = 'Test Task',
        ActivityDate = system.today()
        ));
        
       } 
         insert addtask;        
                                                            
}

 
Hi , i have created a Button on Account object and Now i need to add the visualforce page code Which will create a Contact when the user clicks the button. How to do it
 

Can anyone please help me with this situation?User-added image
HI All,

below is my coding ..

<apex:page standardController="Account" >
<apex:pageBlock  >
    <apex:form >
            <apex:inputField Value="{! Account.AccountNumber}"  /> 
    </apex:form>
    </apex:pageBlock>
</apex:page>

in the output  i am just geting the inputField alone but not its lable why ??
where in i refered some vidio ,where lable is also displayed just by using <apex:inputField Value="{! Account.AccountNumber}"  />
1. Creating a wrapper class Employee with last name, first name, phone, email.
2. SOQL query on Contact to fetch lastName, firstName, Phone, email.
3. Taking one by one contact and creating employee based on the data in the contact
4. Adding to a set
 
public class Employee {
        public String lastName;
        public String firstName;
        public String phone;
        public String email;
}
        List<Contact> contacts = [select FirstName,LastName,Phone,Email from Contact];
<!-- Here it is showing me the ERROR 
       ERROR: Missing '<EOF>' at 'List'        
-->
        Set<Employee> employees =new Set<Employee>();
        
        for(Contact c:contacts){
            
            Employee e =new Employee();
            e.LastName=c.LastName;
            e.firstName=c.firstName;
            e.Phone=c.Phone;
            e.Email =c.Email;
            employees.add(e);
        }

Can someone tell me what is the issue
Hi, 

  I want to extract owner name from below query. 
SELECT  Ownerid,Ownerid.name,
                Userid,User.name,
                opportunityaccesslevel,teammemberrole FROM UserTeamMember
I am getting below error message. not able to get the relation name please suggest me how to extract name in soql query

User-added image

Thanks
  • May 13, 2019
  • Like
  • 0

Hello friends!

I cannot get this visualforce component to save. After trying a lot of different things in setting the properties i still get the error: Unknown property 'SObject.' on line 0.

Any guidance is greatly appreciated.

 

<apex:component controller="pdf_QLineItemGrouped2">

	<apex:attribute name="qlis" required="true" type="QuoteLineItem[]" assignTo="{!qli}" description="List of quote line items to be displayed."/>
    <apex:attribute name="totalPrice" required="true" type="Decimal" description="Quotes total sales price"/>
     <section >
         <b></b>
         <table class="qitable">
             <tr>
                 <th class="row-name label" >Product</th>
                 <th class="row-date label">Description</th>
                 <th class="row-date label">Quantity</th>
                 <th class="row-status label">CPI</th>
                 <th class="row-status label">Total</th>
             </tr>
             
             <apex:repeat var="qli" value="{!groupedQLIs}">
                 
                 <tr>
                     <td class="row-name detail" >{!qli.['Family']}</td>
                     <td class="row-name detail" >{!qli['Quantity']}</td>
                     <td class="row-date detail">
                         <apex:outputText value="{0, number,currency}">
                             <apex:param value="{!qli.['Amount']}"/>
                         </apex:outputText>
                     </td>
                     <td class="row-date detail">
                         <apex:outputText value="{0, number,currency}">
                             <apex:param value="{!qli.TotalPrice}"/>
                         </apex:outputText>
                     </td>
                 </tr>
             </apex:repeat> 
             <tr class="label">
                 <td colspan="4" class="alignRight">Total:</td>
                 <td>
                     <apex:outputText value="{0, number,currency}">
                         <apex:param value="{!totalPrice}"/>
                     </apex:outputText>
                 </td>
             </tr>
         </table>
         <p style="page-break-after: always">Please note that prices do not include GST.</p>
    </section>

</apex:component>
 
public class pdf_QLineItemGrouped2 {
	
    public pdf_QLineItemGrouped2(){}
   public list<QuoteLineItem> qli {get; set;}
   set<Id> qlids = (new Map<Id, QuoteLineItem>(qli)).keySet(); 
   public list<SObject> groupedQLIs {
       get {return groupedQLIs;} 
       private set{
           groupedQLIs = [SELECT 
                       PricebookEntry.Product2.Family Family, 
                       SUM(Quantity) Quantity, 
                       SUM(CG_Total_Price__c) Amount
                       FROM QuoteLineItem
                       WHERE Id IN :qlids AND UnitPrice > 0
                       GROUP BY PricebookEntry.Product2.Family
                       ORDER BY PricebookEntry.Product2.Family ASC];
       }}
}

Hi Community,

I thought this would be an easy formula, but haven't found any solutions posted. 

I have a custom date field, "Deliverable Date" and a custom number field, "Acceptance Period (Days)". 

If the Deliverable Date is 5/12/19 and the Acceptance Period (Days)" is 7, I'd like a fomula to add the 7 days to a custom formula field "Acceptance Date" that results in 5/19/19. And if the days were 6, then the Acceptance Date would be 5/18/19, and so forth.

Would this need to be a workflow vs. formula? Any advice would be appreciated. Thank you!

I have two objects obj1 and obj2
having same fields like Name,phone when i enter Name phone values in obj1 after saving that will be shown obj2 as well how can achieve this
  • April 29, 2019
  • Like
  • 0
Hi, 

I need to write a tigger that will send a different email template based on a date field. 
I have an object called references that is a lookup to the contact, I need to send an email at 60,30 and 10 before the experation date and I cant use process builder or workflow so im REALLY stuck.
Could someone please give me a sample code for a trigger that I can tweek. 

Thank You,

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

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

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

How to do it? It throws error saying non-static methods cannot be referred from static context.
 
  • April 25, 2019
  • Like
  • 0
public class ContactpQueueable implements Queueable {
    public List<Contact> conToInsert = new List<Contact>();
    public List<Contact> conToDeleteList = new List<Contact>();
    
    
    public void execute(QueueableContext context) {
        if(!conToInsert.isEmpty()){
            Database.insert(conToInsert );
        }
        if(!conDeleteList.isEmpty()){
            Database.delete(conToDeleteList);
        }
    }
}
Create a new object Survey Request with below fields,
  1. Status – Pick list(Options: Open, Close , Start, Stop)
  2. Stop Started date – date
  3. Total Stop Duration in days-- Integer
  • Create a trigger on survey request to capture the total days for which the survey request was stopped and store the same in Total Stop Duration in day’s field.
Hello I am trying to add additional string elements to my set<string> collection variable. When I add a new string element (e.g. asset), it seems to be overriding the existing values in the assetCollection variable. Is there a way to add the additonal elements without overiding existing values? 

I've tried the add(string element) method that doesn't seem to be working. Thank you. 

Below are my class and trigger 

Class 

public class AccountActiveProducts {
    
        public static void updateAccounts(List<Asset> assetLists){
                                            
            Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, ProductsOwned__c, (Select Id, ProductFamily__c from Assets Where Id In: Trigger.new) From Account]);                                                   
            Set<String> assetCollection = new Set<String>();
            Set<Id> ParentIds = new Set<Id>();
            List<Account> AccountParent = new List<Account>();
            String a = '';
            Boolean noMatch = false;
           if(Trigger.isInsert || Trigger.isUpdate){ 
                   
                for(Asset asset: assetLists){
                   if(asset.Status!= null ||asset.Status !='Retired' || asset.Status!= 'Obsolete' && asset.AccountId != null )  
                   ParentIds.add(asset.AccountId);
                   assetCollection.add(asset.ProductFamily__c);
                }     
            }
            
               if(Trigger.isDelete){ 
                   
                for(Asset assetOld: assetLists){
                   if(assetOld.Status!= null && assetOld.Status !='Retired' && assetOld.Status!= 'Obsolete' && assetOld.AccountId != null )  
                   ParentIds.add(assetOld.AccountId);
                }     
            }
            
            for(Account account: [Select Id, ProductsOwned__c from Account where Id In: ParentIds]){
                
                a =+ '' + string.valueOf(assetCollection);
                mapAccount.put(account.id, account);
                
            }
            
            if(ParentIds.size() >0){
                
                List<Asset> assetList = new List<Asset>([Select Id, AccountId, Status, ProductFamily__c from Asset where
                                                        AccountId IN: ParentIds]);
                List<Account> accountList = new List<Account>([Select Id, ProductsOwned__c from Account where
                                                        Id IN: ParentIds]);
                
                               
                for(Account accountP: accountList){
         
                    for(Asset asstc: assetList){
                        if(asstc.AccountId == accountP.Id)
                        
                          for(String s: assetCollection){
                              //If assetCollection doesn't contain the string element, then add that string element to the collection
                              if(!assetCollection.contains(s) && asstc.Status!= null && asstc.Status !='Retired' && asstc.Status!= 'Obsolete' && assetCollection.isEmpty()){
                                  noMatch = false;
                              assetCollection.add(asstc.ProductFamily__c); 
                      //           assetCollection.add(s); 
                                 String outputString = String.join(new List<String>(assetCollection), ',');
                               a =+  string.valueOf(assetCollection).replaceAll('[{||}]','') + ', ' + asstc.ProductFamily__c;
                       //          a =+  outputString.replaceAll('[{||}]','');
                              }
                              else if(assetCollection.contains(s) && asstc.Status!= null && asstc.Status !='Retired' && asstc.Status!= 'Obsolete' && assetCollection.contains(asstc.ProductFamily__c)){
                                  noMatch = true;
                                  
                                  String outputString = String.join(new List<String>(assetCollection), ',');
                                  a =  string.valueOf(assetCollection).replaceAll('[{||}]','');
                              }
                              
                                  else if(asstc.Status =='Retired' || asstc.Status== 'Obsolete' || asstc.Status== null &&  assetCollection.contains(asstc.ProductFamily__c)){
                                  noMatch = false;
                                  assetCollection.remove(asstc.ProductFamily__c);
                              }
                           
                    }
                        
                    }
              
                    accountP.ProductsOwned__c = a;
                    
                }
                
                try{
                    upsert accountList;
                }
                
                catch(Exception ex){
                    System.debug('Exception is ' + ex);
                    
                }            
            }        
            }
}


Trigger 

trigger AssetPrimaryTrigger on Asset (before insert, before update, after insert, after update, before delete, after delete) {
    if(Trigger.isBefore){
        if(Trigger.isInsert){   
        }
        if(Trigger.isUpdate){
                    }
        if(Trigger.isDelete){
                    }
        
    }
    
 if(Trigger.isAfter){
        if(Trigger.isInsert){ 
           
        }
        if(Trigger.isUpdate){
             AccountActiveProducts.updateAccounts(trigger.new);
                    }
        if(Trigger.isDelete){
                    }
        
    }    
    

}
  • April 22, 2019
  • Like
  • 0
Hi People,
I have written the folloing VF page usin custom controller and a test class. I am getting the following error. Plase help me solve this error

12:05:46:160 FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]
VF Page: showContacts

<apex:page controller="showContactsController" tabstyle="Account">
  <apex:pageBlock title="Recent Contacts">
  <apex:pageblockTable value="{!conList}" var="con">
  <apex:column >
  <apex:facet name="header">Salesforce Id</apex:facet>
  <apex:outputText value="{!con.id}"/>
  </apex:column>
  <apex:column >
  <apex:facet name="header">Name</apex:facet>
  <apex:outputText value="{!con.NAme}"/>
  </apex:column>
  </apex:pageblockTable>>
  </apex:pageBlock>
  
  <apex:form >
  <apex:pageBlock title="Redirect">
  <apex:commandButton value="Go To My Custom Page" action="{!doSubmit}"/>
  </apex:pageBlock>
  </apex:form>
  
  <apex:form >
  <apex:pageBlock title="Contact Form">
  FIRST NAME:<apex:inputText value="{!con.FirstName}"/><br/><br/>
  LAST NAME: <apex:inputText value="{!con.LastName}"/>
  </apex:pageBlock>
  <apex:commandButton value="Save" action="{!save}"/>
  </apex:form>
</apex:page>

Controller:  showContactsController

public with sharing class showContactsController {
    public List<Contact> conList{get;set;}
    public Contact con{get;set;}
    public showContactsController(){
        con = new  Contact();
        conList = [Select id,LastName,Name,Phone from Contact LIMIT 10];
    }
    
    public pagereference doSubmit(){
    pagereference pageRef = new pagereference('/apex/PaginationRecords');
    pageRef.setRedirect(true);
    return pageRef;
    }
    
    public pagereference save(){
        if(!String.isBlank(con.LastName))
            System.debug('LastName------------>'+con.LastName);
    insert con;
        System.debug('Contact id---------->'+con.id);
    return new pagereference('/'+con.id);
    }
}

Test Class for Controller: 
@isTest
public class showContactsController_Test {

    public static testMethod void controllerTest(){
        Account acc = new Account(Name='Test');
        insert acc;
        
        Contact con = new Contact(LastName='Test12',Phone='852149633',AccountId=acc.Id);
        insert con;
        
        Pagereference pageRef = Page.showContacts;
        pageRef.getParameters().put('LastName','Test123');
        pageRef.getParameters().put('id',con.id);
        Test.setCurrentPage(pageRef);
        
        Test.startTest();
        showContactsController controller = new showContactsController();
        PageReference pr1 = controller.doSubmit();
        Pagereference pr2 = controller.save();
        Test.stopTest();
        System.assertEquals(pr2.getUrl(),'/'+con.Id);
    }
}
 
Is it possible to deploy an unmanaged package created from a Developer ORG to a production org. The reason being is that as you know, you cannot create a Sandbox ORG with a Developer ORG. And you cant create code "directly" on a production server
Whenever existing Account is updated with  AnnualReneue  more than 10k and Industry as Technology  then create a new opportunity for this account with same account name, stage name prospecting...

 
  • January 16, 2019
  • Like
  • 0
the trigger should be on account to check the assets and if ALL the Assets belonging to product family = "bla bla " had their status "Canceled" the trigger should update bla bla Account stage (API Name = Account_Status__c ) to "Cancel".

below is a trigger I wrote but it doesn't work

trigger cancelAsset on Account (after update) {

    
    List<Asset> suite = [Select Id ,Status from Asset where Product_Family__c = '360 Suite']; 
    List<Asset> tech = [Select Id ,Status from Asset where Product_Family__c = 'Ad Tech']; 
    for(Account acc:Trigger.new){
        
        Integer z=0;
        for(Integer i=0 ; i<= suite.size() ;i++){
            if(suite[i].Status == 'Canceled'){
              z++;
            }
        }
        
        if (z == suite.size()){
            acc.Account_Status__c = 'Cancel';
        }
        update acc;
    }
}

 
Hi All,

How to erase value from text field while updating record?

Reauirement :
i have one text field, while creating a record it is required field and while updating same record, i would be erase value from text field.?

please let me know how can i achive this .Give me example code also.

Thanks in advance.
China