• Simha Yadav
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 17
    Replies
Hi All, 
I am new to Salesforce.
I want to update contact records when task fields are updated. (I have WhoId in Task)
I have 3 fields in Task : F1__C, f2__C, f3__C.
I have 3 fileds in Contact : CF1__c, CF2__c, CF3__c

When ever the 3 fileds updated in Task, I want to update same values to contact.

How to write trigger for this?

Please help me
Thanks in Advance!!
I'm trying to better understand how field level security works with fields being required through page layouts. It seems there are 4 ways, you can make a field required:
1. When you create the field, you can tick the box to make it required
2. Through the page layout by clicking on the spanner/wrench next to the field
3.  Go to the object - Fields, click on the field name (not edit or del) and you can select "required"
4.  Go to Security Controls | Field accessiblilty, select the object, then the field and then you can edit through field access
What's confusing to me is field level security makes me think this is what you would use to make a field required, but it only allows you to select 'Visible' or 'Read'.

This came from trying to answer this question:
A custom field is made Read only from the Field level security and Required from Page layout. The Field will be?  
A. Read Only for the User

B. Required for the User
C. Throws an error and don’t allow to make Read only field Mandatory from page layout
D. User is given a choice in a pop-up window


The Quiz gave the answer as A, but I tested it and find the answer is B.
Would appreciate any input on whether i'm understanding all this accurately - thank you!
Hi All,

I have written a batch class with the below scenario.
if (ObjectName==Account)
{ need to query account  records
}
else if (ObjectName =Contact )
{ Query Contact records)
}
So i will get either account or contact records in scope and in execute method i will create records for other custom object means if it is account it will insert with account Id in the new custom object and if Contact contact Id in the new object .Right now it is captuirng the Id into another custom Object but the problem is whenever i am executing it is capturing the same .

So here i want to eliminate the creation of duplicates means if the Record Id(Acc or con Id already in the new custom object then it should not create new record if the record is not existing then create new record with the Acc or Con Id

My Code:
  global void execute(Database.BatchableContext BC, List<SObject> scope)
    { 
        Map<id, Custom Object> CustomMap= new Map<id,Custom Map>();
         for(Sobject obj: scope)
         {      
                Custom Object cm= new Custom Object();
                 
                 cm.Recordt_ID__c =obj.Id;
                 
                  CustomMap.put(Cm.Object_ID__c, cm);
             
          }
          if(!CustomMap.isEmpty())
        {
            Database.SaveResult[] InsertResult = Database.insert(CustomMap.values(),false);
            
        }
        
    }

So here how i will check if there is already a record with same Object Id is there then it should not insert if it is not there it should create new custom object Record.Any one please guide how to do this

Thanks in advance
please look at this pic
<apex:page controller="Pagination_min"  showHeader="false" sidebar="false"  extensions="AccountController">
  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection columns="1"  title="Accounts"> 
            <apex:pageBlockTable value="{!accounts}" var="a">
                <apex:column >
                   <apex:outputLink title="" value="/{!a.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;

                </apex:column>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Type}"/>
                <apex:column value="{!a.BillingCity}"/>
                <apex:column value="{!a.BillingState}"/>
                <apex:column value="{!a.BillingCountry}"/>
            </apex:pageBlockTable>
            <apex:panelGrid columns="7">
            <apex:commandButton value="|<" action="{!setcon.first}" disabled="{!!setcon.hasPrevious}" title="First page"/>
            <apex:commandButton value="<" action="{!setcon.previous}" disabled="{!!setcon.hasPrevious}" title="Previous page"/>
            <apex:commandButton value=">" action="{!setcon.next}" disabled="{!!setcon.hasNext}" title="Next page"/>
            <apex:commandButton value=">|" action="{!setcon.last}" disabled="{!!setcon.hasNext}" title="Last page"/>
           
             <apex:outputText >{!(setCon.pageNumber * size)+1-size}   -    {!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton value="Refresh" action="{!refresh}" title="Refresh Page"/>
            </apex:panelGrid>
        </apex:pageBlockSection>
     </apex:pageBlock>
                      <apex:pageBlock title="My Content" mode="edit">
                          <apex:pageBlockButtons >
                               <apex:commandButton action="{!save}" value="Save" reRender="pb"/>
                          </apex:pageBlockButtons>
                               <apex:pageBlockSection title="My Content Section" columns="2">
                                    <apex:inputField value="{!account.name}" required="false"/>
                                    <apex:inputField value="{!account.type}"/>
                                    <apex:inputField value="{!account.Billingcity}"/>
                                    <apex:inputField value="{!account.billingstate}"/>
                                    <apex:inputField value="{!account.billingcountry}"/>
                               </apex:pageBlockSection>
                      </apex:pageBlock>
  </apex:form>               
</apex:page>
**************************************************************************************
public class Pagination_min {

    Public Integer noofRecords {get; set;}
    public integer size {get; set;}
   
    public Apexpages.standardsetController setcon{
        get{
            if(setCon == null){
                size = 10;
                String queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
                setcon = new apexpages.standardsetController(Database.getquerylocator(queryString));
                setcon.setpagesize(size);
                noofRecords = setcon.getResultsize();
            }
            return setcon;
        }
         set;
    }
    Public list<Account> getAccounts(){
        list<Account> acclist = new list<Account>();
         for(Account ac : (list<Account>)setcon.getrecords()){
             acclist.add(ac);
         }
        return accList;
       
      
    }
   Public PageReference Refresh(){
       
        setcon=null;
        getAccounts();
        setcon.setpageNumber(1);
       
        return null;
    }
}
**********************************************************************
public with sharing class AccountController {
   
    public Account account{get; set;}
    public AccountController(Pagination_min controller) {
      account = new Account();
    }
    
    public void save(){
        upsert account;
    }
}
whenever we create a record in any object that record will be visible to to the custom object record using apex code or anyway

please letme know how we can do that
Can anyone tell the best practices of tracking the tasks?
Hi Folks,

i have two custom fields in both account and conatct i,e state and city now i want to make auto populate for those fields in contact when i try to create new contact in related list.
VF Code:
<apex:page standardController="Account" extensions="WrapperDemoClass" showHeader="false" sidebar="false">
  <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");                  
            for(var i=0; i<inputCheckBox.length; i++){          
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){                                     
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
  <apex:form >
    <apex:pageBlock title=" Account Invoice" id="pgBlckId">
    <br/>
    <br/>
     <apex:commandButton value="Send Email" action="{!sendEmail}" reRender="pgBlckId" status="actStatusId" />
     &nbsp;
       <apex:actionStatus id="actStatusId" >
       <apex:facet name="start" >
       <apex:image url="{!$Resource.Image}"/>
       </apex:facet>
       </apex:actionStatus>
     <br/>
     <br/>
     <apex:pageMessages />
     <br/>
       <apex:pageblockTable value="{!wrapperObj}" var="Rec" id="table" title="All Accounts">
         <apex:column >      
         <apex:facet name="header">
         <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
         </apex:facet>
         <apex:inputCheckbox value="{!Rec.checkBox}" id="inputId"/>
         </apex:column>
         <apex:column value="{!Rec.accObj.name}"/>
         <apex:column value="{!Rec.accObj.phone}"/>
         <apex:column value="{!Rec.accObj.Email__c}"/>
         <apex:column value="{!Rec.accObj.createddate}"/>
         <apex:column value="{!Rec.accObj.Email_Status__c}"/>
      </apex:pageblockTable> 
    </apex:pageblock>
  </apex:form>
</apex:page>

Apex Class:

public with sharing class WrapperDemoClass {
    Public List<WrapperClassEx> WrapperList{get;set;}
    public List<Account> accList {get;set;}
    public boolean checked {get;set;}
    public WrapperDemoClass(ApexPages.StandardController controller) {
      
    }
   
   Public List<WrapperClassEx> getwrapperObj(){
      accList = [Select id,name,phone,type,industry,Email__c,createddate,Email_Status__c from account limit 15];
      WrapperList = New List<WrapperClassEx>();
      for(Account acc: accList){
        WrapperList.add(New WrapperClassEx(acc,false)); 
      }
      system.debug('WrapperList :'+WrapperList);
      return WrapperList;
   }
   
   public void sendEmail(){
     List<Messaging.SingleEmailMessage> lstEmailId=new List<Messaging.SingleEmailMessage>();
     
         PageReference pdf = Page.newreq;
        // add parent id to the parameters for standardcontroller
        //pdf.getParameters().put('id',accountId);
    
        // the contents of the attachment from the pdf
        Blob body;
    
        try {
    
          // returns the output of the page as a PDF
          body = pdf.getContent();
    
        // need to pass unit test -- current bug  
        } catch (VisualforceException e) {
          body = Blob.valueOf('Some Text');
        }
    
       
     
     for(WrapperClassEx w: WrapperList){
        system.debug('w.checkBox :'+w.checkBox);
        if(w.checkBox == true){
            
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setContentType('application/pdf');
            attach.setFileName('Invoice.pdf');
            attach.setInline(false);
            attach.Body = body;
            
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(new String[] {w.accObj.Email__c});
            //mail.setReplyTo('sumit.shukla@magicsw.com');
            mail.setplainTextBody('Hello');
            mail.setSenderDisplayName('Your Company Name');
            mail.setSubject('Test Email From Force.com Sites');
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 
            lstEmailId.add(mail);
            system.debug('lstEmailId :'+lstEmailId);                        
        }
      }
        if(lstEmailId.size()>0){
            try{
                Messaging.sendEmail(lstEmailId);
                checked = true;
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Confirm,'Sent!'));
            }Catch(Exception ee){
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Error,ee.getMessage()));
            }
            
        }
      
    }     
   

  
   Public Class WrapperClassEx{
     Public Account accObj{get;set;}
     Public Boolean checkBox{get;set;}
    
     Public WrapperClassEx(Account accRec, boolean SelectBox){
        accObj = accRec;
        checkBox = SelectBox;
     }
   }
}


 
i created standard account query list in that i added CreatedDate filed and displaying format on vf like this 18/10/2014 10:13 AM but i dont want to display time here please give anybody solution.
Can anybody give code for below scenerio?
1.Send email using apex while updating record.
  - create trigger on after update
  - create class and write logic to send email
  - call class from trigger

Hello Everyone

 

Any help would be greatly appreciated

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Product_Detail__c> at line 274 column 24

 

  public string SelectedAccountId { get; set; }
     public void DeleteDetail()
   {
    // if for any reason we are missing the reference
      if (SelectedAccountId == null) {     
         return;
      }
    
      // find the detail record within the collection
      Product_Detail__c tobeDeleted = null;
     
      for(List<Product_Detail__c> a : products.values())
     // for(Product_Detail__c a : products)
       if (a.name = SelectedAccountId) {
         tobeDeleted = a.name;    <<<<<<Line 274
          break;         
        }     
      //if account record found delete it
      if (tobeDeleted != null) {
       Delete tobeDeleted;
      }
    
      //refresh the data
      //LoadData();
   }