• AnnaT
  • NEWBIE
  • 30 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 38
    Replies

Hi all,

 

I created the following Visualforce Page. This page is shown when [Edit] button is clicked.

If there is an attachment, <apex:inputFile> is hidden. But if "Remove Attachfile" link is clicked, <apex:inputFile> will be shown.

 

The problem is that, when <apex:inputFile> is changed from "hidden" to "shown" and new attachment is attached and [Save] button is clicked, no attachment is attached...

 

I think it is Visualforce problem, especially "rendered" problem, because when <apex:inputFile> is originally shown, it works properly.

I can't solve this problem... Please help me...

 

<apex:page standardController="Sample__c" extensions="Sample_Ext">  
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockButtons location="top">
        <apex:commandButton value="Save" action="{!save}" />
        <apex:commandButton value="Cancel" action="{!Cancel}"/>
      </apex:pageBlockButtons>
      <apex:actionRegion >
        <apex:pageBlockSection title="Attachment Section" columns="3" id="BS1" >
          <apex:pageBlockSectionItem rendered="{!isAttached1}" dataStyle="width:10%">
            <apex:commandLink value="{!attachment1.Name}" action="{!downloadAttachment}" target="_blank" >
              <apex:param name="attachId" value="{!attachment1.Id}" />
            </apex:commandLink>
            <apex:commandLink value="[Remove Attachfile]" action="{!Remove}" onclick="if(!confirm('Are you sure?')){return false;}" reRender="BS1">
              <apex:param name="removeId" value="remove1" />
            </apex:commandLink>
          </apex:pageblocksectionitem>
          <apex:pageBlockSectionItem rendered="{!isAttached1==False}" dataStyle="width:10%">
            <apex:inputFile value="{!file1Content}" fileName="{!file1Name}"/>
          </apex:pageblocksectionitem>
        </apex:pageBlockSection>
      </apex:actionRegion>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

 Thanks in advance for your help.

 

Anna 

  • November 07, 2013
  • Like
  • 1

Please refer to the following code.

I'd like to use "objList" in Visualforce Page with some paging function

( for example, setCon.getHasPrevious(), setCon.getHasNext(), and so on...).

But I don't know how to set "objLIst" into ApexPages.StandardSetController.

I know I can set "rftList". but I need to use "objList".

 

A part of my code is this.

public with sharing class BulkAccept {

    // Inner Class Definition
    public Class RFT_Category_for_Select {        
        public Boolean checkAccept {get;set;}
        public Boolean checkNa {get;set;}
        public RFT_Category__c obj {get;set;}        
    }    

    // Property 
    public List<RFT_Category_for_Select> objList{get;set;}

    // Constructor
    public BulkAccept() {
        this.objList = new List<RFT_Category_for_Select>();  
        List<RFT_Category__c> rftList = [
            SELECT Id, Name 
              FROM RFT_Category__c 
             WHERE Reject__c = false
             ORDER BY Name
        ];
        for (RFT_Category__c rft : rftList) {
            RFT_Category_for_Select objItem = new RFT_Category_for_Select();
            objItem.checkAccept = false;
            objItem.checkNa     = false;
            objItem.obj         = rft;
            this.objList.add(objItem);
        }
        this.setCon = new ApexPages.StandardSetController(objList);
        this.setCon.setPageSize(50);     
    }

 Thanks in advance for your help.

 

Anna 

 

 

 

  • August 06, 2013
  • Like
  • 0

Please help me...

 

When I update over 1000 items at the same time, "System.LimitException: Too many code statements: 200001" error occurs.

I know the meaning of this error but I don't know how to modify my code...

Hereis a part of my Trigger;

if (Trigger.isInsert || Trigger.isUpdate) {
  List<ParentObject__c> pList = new List<ParentObject__c>();
  for (ChildObject__c chld : Trigger.new) {
    ParentObject__c pObj = new ParentObject__c();
    pObj.Id=chld.ParentLookupField__c;
    Boolean flag = false;
    if(pList.size()==0){
      pList.add(pObj);
    }
    for(integer i=0;i<pList.size();i++){
      if(pList[i].id==pObj.Id){
        flag=true;
      }else if(flag==false){
        pList.add(pObj);
      }
    }    
  }
  update pdList; 
}

 

Thanks in advance for your support...

 

Anna

 

  • June 25, 2013
  • Like
  • 0

Please help me...

 

I have 20 E-mail fields named Email1__c, Email2__c, Email3__c,.....Email20__c.

What I want to do is loop thorugh these fields and input value.

 

Hereis my code.

Alerts__c alerts =new Alerts__c();
for(integer j=1;j==MailList.size();j++){
  String iStr = String.Valueof(j);
  String fieldname='Email'+iStr+'__c';
  alerts.get(fieldname)='test@test.com';
}

 But the following error occured.

 Expression cannot be assigned 

 

Please tell me how to solve this problem...

 

Thanks in advance for your help.

 

Anna

 

  • June 14, 2013
  • Like
  • 0

The following error occurrs but I don't know how to solve this.

 

MALFORMED_QUERY: childObj__r where Location__c = :tmpVar1) from ParentObj__c ^ ERROR at Row:1:Column:227 unexpected token: ':'

[Select r.Name,r.Id,
         (Select Status__c 
           From childObj__r 
          WHERE Location__c=:location )  
   From ParentObj__c r 
  where r.Location__c includes (:location) order by r.Name]));

 Thanks in advance for your help!

Anna

 

  • April 19, 2013
  • Like
  • 0

I'd like to show both parent and child objects in one table.

But I don't know how to show "Status__c" in VF page.

Please help me...

 

Here is my code.

 

  part of my Apex class.

setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
         [Select r.Phase__c, r.Name, 
                 r.Item_No_seq__c, r.Id,
                 (Select Status__c From Ichthys_RFT__r)  
            From RFT_Category__c r 
           where r.Location__c includes (:location) order by r.Item_No_seq__c]));

 my VF page.

 If I try to save this code, the error occurrs. "Error: Unknown property 'VisualforceArrayList.Status__c'"

<apex:pageBlockTable id="block" value="{!lstREFCategory}" var="rftObject" style="width:100%" >
  <apex:column headerValue="No" >
  <apex:Outputtext value="{0,number,###,###,###,###}">
  <apex:param value="{!rftObject.Item_No_seq__c}"></apex:param>
  </apex:outputtext>
  </apex:column>
  <apex:column style="width:200px"  >
    <apex:facet name="header">
        Phase
    </apex:facet>
    <apex:Outputtext value="{!rftObject.Phase__c}" style="width:50px" />
  </apex:column>
  <apex:column headerValue="Status">
  <apex:Outputtext value="{!rftObject.Ichthys_RFT__r.Status__c}" style="width:200px"/>
  </apex:column>
</apex:pageBlockTable>

 Thank you,

 Anna

  • April 15, 2013
  • Like
  • 0

When I update data, the following trigger can't get "Item_No_seq__c" value.

Please tell me what is a problem...

 

trigger IchthysRFT on RFT_Category__c (before insert, before update) {
  Map<String,Map<Double,RFT_Category__c>> rft =
    new Map<String,Map<Double,RFT_Category__c>>();
  
  Set<String> objNos = new Set<String>();
  Set<Double> itemSeq = new Set<Double>();
  for(RFT_Category__c record:trigger.new) {
    objNos.add(record.Object_No__c);
    itemSeq.add(record.Item_No_seq__c);
  }
  for(RFT_Category__c record:[SELECT Id, Item_No_seq__c, Object_No__c
                                FROM RFT_Category__c
                               WHERE Object_No__c IN :objNos AND Item_No_seq__c!=null 
                               ORDER BY Item_No_seq__c DESC limit 1]) {
    if(!rft.containsKey(record.Object_No__c)) {
      rft.put(record.Object_No__c,new Map<Double,RFT_Category__c>());
    }
    rft.get(record.Object_No__c).put(record.Item_No_seq__c,record);
  }
  for(RFT_Category__c record:Trigger.new) {
    if(rft.containsKey(record.Object_No__c)&& rft.get(record.Object_No__c).containsKey(record.Item_No_seq__c)) {
      RFT_Category__c tmp = rft.get(record.Object_No__c).get(record.Item_No_seq__c);
      if(Trigger.isUpdate){
        RFT_Category__c oldpd=Trigger.oldMap.get(record.id);
        if(record.Object_No__c!= oldpd.Object_No__c){
          record.Item_No_seq__c = tmp.Item_No_seq__c +1;
        }
      }
    }else {
      record.Item_No_seq__c = 1;
    }
  }
}

 

Thank you,

Anna

  • March 28, 2013
  • Like
  • 0

When I update one record, this trigger works, but when I update multiple records by using Apex Dataloader, it doesn't work.

This trigger updates parent object when its child object's status is updated.

 

1. Child object Trigger: it just updates parent object.

trigger RFTSetPDStatusFromMS on Ichthys_RFT__c(after insert, after update) {
    
  if (Trigger.isInsert||Trigger.isUpdate)
  {
    list<Ichthys_RFT__c>msl=[SELECT id,Status__c,RFT_Category__r.Id FROM Ichthys_RFT__c WHERE Id in :Trigger.new];
    Ichthys_RFT__c newMs=null;
    if(msl.size()>0)
    {
      newMs=msl[0]; 
      RFT_Category__c[] pdList = [SELECT id, Name, PD_Status__c FROM RFT_Category__c WHERE Id = :newMs.RFT_Category__r.Id];
      if(pdList.size()>0)
      {
        update pdList[0];
      }
    }
  }
}

2. Parent Object Trigger: it checks child object status and update parent status.

trigger RFTSetPDStatus on RFT_Category__c (before update) {
  if (Trigger.isUpdate)
  {
    List<Ichthys_RFT__c > msList= [SELECT RFT_Category__r.Id,Status__c FROM Ichthys_RFT__c WHERE RFT_Category__r.Id in :Trigger.new];
    Integer msExist=0;
    Integer msCnt=0;  

    if(msList.size()>0){
      msExist +=1;
    }
    for(RFT_Category__c pd:Trigger.new){
      if(msExist==0){
        pd.PD_Status__c ='Open';
      }else{
        for( Ichthys_RFT__c ms :msList){
          if( ms.RFT_Category__r.Id == pd.Id && ms.Status__c <>'Completed' &&  ms.Status__c <>'Not Applicable'){
            msCnt +=1;
          }
        }
        if(msCnt==0){
          pd.PD_Status__c ='Close';
        }
        else if(msCnt>0){
          pd.PD_Status__c ='Open';
        }
      }
    }
  }
}

 Thanks in advance for your help.

 

Anna

 

  • March 26, 2013
  • Like
  • 0

When I use apex dataloader to insert multiple data, the following error occurres.

"System.LimitException: Too many code statements: 200001"

Is it because I use List ?

trigger RFTSetPDStatus on RFT_Category__c (before insert, before update) {
 List<Ichthys_RFT__c > msList= [SELECT RFT_Category__r.Id,Status__c FROM Ichthys_RFT__c ];
  if (Trigger.isInsert)
  { 
    for(RFT_Category__c pd:Trigger.new)
    {
        pd.PD_Status__c='Open';      
    }
  }
  else if (Trigger.isUpdate)
  {
    Integer msExist=0;
    Integer msCnt=0;  
    for(RFT_Category__c pd:Trigger.new)
    {
      for( Ichthys_RFT__c ms :msList){
        if( ms.RFT_Category__r.Id == pd.Id ){
          msExist +=1;
        }
      }
      if(msExist==0)
      {
        pd.PD_Status__c ='Open';
      }
      else
      {
        for( Ichthys_RFT__c ms :msList){
          if( ms.RFT_Category__r.Id == pd.Id && ms.Status__c <>'Completed' &&  ms.Status__c <>'Not Applicable'){
            msCnt +=1;
          }
        }
          if(msCnt==0)
          {
            pd.PD_Status__c ='Close';
          }
          else if(msCnt>0)
          {
            pd.PD_Status__c ='Open';
          }
        }
    }
  }
}

Thank you,

Anna

  • March 26, 2013
  • Like
  • 0

Please help me...

 

When I insert or update data, the following trigger sends email.

This trigger works when insert or update one data.

But when I try to insert or update multiple data by Apex Data Loader, error occurs.

How can I solve this error?

 

<error>

PDSendEmailtoOC: execution of AfterUpdate
caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []
Trigger.PDSendEmailtoOC: line 161, column 1
 
trigger PDSendEmailtoOC on RFT_Category__c (after insert,after update) {

  List<RFT_Category__c > pdList= [SELECT Location__c,Object_No__c FROM RFT_Category__c ];
  List<Object_Champion__c> ocList=[SELECT Location__c,Object_No__c,Champion_email__c FROM Object_Champion__c];
  List<AreaCoordinators__c> acList=[SELECT Area__c, Group_Mail_Address__c FROM AreaCoordinators__c];
  String recipient = '';
  List<String> toAddresses= new List<String>();
  List<String> ccAddress = new List<String>();
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  
  for (RFT_Category__c rft : Trigger.new) {
  
    //Rejectの場合、InitiatorにMail
    if(rft.Reject__c==TRUE && rft.E_mail_Address__c<>null){
      //更新前のデータのRejectがFalseの場合のみ送信
      if(trigger.oldMap.get(rft.id).Reject__c==FALSE){
        recipient = rft.E_mail_Address__c;
      
        //一時的にContactを作成。setTargetObjectIdでContactを指定しないとsetWhatIDでCustomObjectを指定できないため。
        Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
        insert tempContact;

        toAddresses.add(rft.E_mail_Address__c);
        mail.setSenderDisplayName('RFT Auto Mail');
        mail.setTemplateId('00XN0000000DbBw');
        mail.saveAsActivity = false;
        mail.setTargetObjectId(tempContact.id);
        mail.setWhatId(rft.Id); 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      
        //Contact削除
        delete tempContact;
      }
    }else if(rft.Location__c<>null && rft.Object_No__c<>null){
    //Rejectでない場合、割り振られたLocationのArea CoordinatorとObjective Champion、InitiatorにMail。変更がない場合はなにもしない。
  
      String [] locationList = rft.Location__c.split(';');
  
      //ObjectNoが異なる場合。
    
      if(Trigger.isUpdate){
        if(trigger.oldMap.get(rft.id).Object_No__c==null || trigger.oldMap.get(rft.id).Object_No__c<>rft.Object_No__c){

          //Set recipients
          for(integer i=0; i<locationList.size(); i++){
        
            //Object Championの宛先設定
            for( Object_Champion__c oc :ocList){
              if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
                String [] OCMailList = oc.Champion_email__c.split(';');
                for(integer j=0; j< OCMailList.size(); j++){
                  if(i==0&&j==0){
                    recipient=OCMailList[j];
                  }else{
                    toAddresses.add (OCMailList[j]);
                  }
                }
              }             
            }
            //Area Coordinatorの宛先設定
            for(AreaCoordinators__c ac :acList){
              if(ac.Area__c == locationList[i]){
                String [] ACMailList = ac.Group_Mail_Address__c .split(';');
                for(integer m=0; m< ACMailList .size(); m++){
                  toAddresses.add (ACMailList[m]);
                }
              }
            }
          } 
          Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
          insert tempContact;
          if(rft.E_mail_Address__c<>null){
            ccAddress.add(rft.E_mail_Address__c);
            mail.setCcAddresses(ccAddress);
          }
          mail.setTargetObjectId(tempContact.id);
          mail.setToAddresses(toAddresses);
          mail.setSenderDisplayName('RFT Auto Mail');
          mail.setTemplateId('00XN0000000DbB3');
          mail.saveAsActivity = false;
          mail.setWhatId(rft.Id);
          Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
          delete tempContact;
    
        //ロケーションが異なる場合。
        }else if(trigger.oldMap.get(rft.id).Location__c<>rft.Location__c) {
        
          //古いデータのLocationが空の場合
          if(trigger.oldMap.get(rft.id).Location__c==null){
            for(integer i=0; i<locationList.size();i++){
              for( Object_Champion__c oc :ocList){
                if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
                  String [] OCMailList = oc.Champion_email__c.split(';');
                  for(integer k=0; k< OCMailList.size(); k++){
                    if(recipient==''){ 
                      recipient=OCMailList[k];
                    }else{
                      toAddresses.add (OCMailList[k]);
                    }
                  }
                }             
              }
              //Area Coordinatorの宛先設定
              for(AreaCoordinators__c ac :acList){
                if(ac.Area__c == locationList[i]){
                  String [] ACMailList = ac.Group_Mail_Address__c .split(';');
                  for(integer m=0; m< ACMailList .size(); m++){
                    toAddresses.add (ACMailList[m]);
                  }
                }
              }
            }
          }else{   //古いデータのLocationが空でない場合
            String [] oldLocationList = trigger.oldMap.get(rft.id).Location__c.split(';');
            for(integer i=0; i<locationList.size();i++){
              integer cnt = 0;
              for(integer j=0; j<oldLocationList .size(); j++){
                if(LocationList[i]==oldLocationList[j]){
                  cnt=cnt+1;
                }
              }
              if(cnt==0){ //locationList[i]の宛先設定
                //Object Championの宛先設定
               for( Object_Champion__c oc :ocList){
                  if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
                    String [] OCMailList = oc.Champion_email__c.split(';');
                    for(integer k=0; k< OCMailList.size(); k++){
                      if(recipient==''){
                        recipient=OCMailList[k];
                      }else{
                        toAddresses.add (OCMailList[k]);
                      }
                    }
                  }             
                }
                //Area Coordinatorの宛先設定
                for(AreaCoordinators__c ac :acList){
                  if(ac.Area__c == locationList[i]){
                    String [] ACMailList = ac.Group_Mail_Address__c .split(';');
                    for(integer m=0; m< ACMailList .size(); m++){
                      toAddresses.add (ACMailList[m]);
                    }
                  }
                }  
              }       
            }
          } 
          if(recipient<>''){
            Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
            insert tempContact;
            if(rft.E_mail_Address__c<>null){
              ccAddress.add(rft.E_mail_Address__c);
              mail.setCcAddresses(ccAddress);
            }
            mail.setTargetObjectId(tempContact.id);
            mail.setToAddresses(toAddresses);
            mail.setSenderDisplayName('RFT Auto Mail');
            mail.setTemplateId('00XN0000000DbB3');
            mail.saveAsActivity = false;
            mail.setWhatId(rft.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            delete tempContact;     
          }
        }
      }else if(Trigger.isInsert){
        //Set recipients
        for(integer i=0; i<locationList.size(); i++){
        
          //Object Championの宛先設定
          for( Object_Champion__c oc :ocList){
            if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
              String [] OCMailList = oc.Champion_email__c.split(';');
              for(integer j=0; j< OCMailList.size(); j++){
                if(i==0&&j==0){
                  recipient=OCMailList[j];
                }else{
                  toAddresses.add (OCMailList[j]);
                }
              }
            }             
          }
          //Area Coordinatorの宛先設定
          for(AreaCoordinators__c ac :acList){
            if(ac.Area__c == locationList[i]){
              String [] ACMailList = ac.Group_Mail_Address__c .split(';');
              for(integer m=0; m< ACMailList .size(); m++){
                toAddresses.add (ACMailList[m]);
              }
            }
          }
        } 
        Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
        insert tempContact;
        if(rft.E_mail_Address__c<>null){
          ccAddress.add(rft.E_mail_Address__c);
          mail.setCcAddresses(ccAddress);
        }
        mail.setTargetObjectId(tempContact.id);
        mail.setToAddresses(toAddresses);
        
        mail.setSenderDisplayName('RFT Auto Mail');
        mail.setTemplateId('00XN0000000DbB3');
        mail.saveAsActivity = false;
        mail.setWhatId(rft.Id);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        delete tempContact;
      } 
    }
  }
}

 

Thanks in advance for your help!!

 

Anna

  • March 08, 2013
  • Like
  • 0

Could you help me??

I created the followin trigger which sends e-mail when RFT_Category__c is updated.

But when I try to update it, the error occurrs.

"Apex trigger PDSendEmailtoOC caused an unexpected exception, contact your administrator: PDSendEmailtoOC: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: []: Trigger.PDSendEmailtoOC: line 26, column 1"

 

trigger PDSendEmailtoOC on RFT_Category__c (after update) {

  List<RFT_Category__c > pdList= [SELECT Location__c,Object_No__c FROM RFT_Category__c ];
  List<Object_Champion__c> ocList=[SELECT Location__c,Object_No__c,Champion_email__c FROM Object_Champion__c];
  
  for (RFT_Category__c rft : Trigger.new) {
    
    String [] locationList = rft.Location__c.split(';');
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    List<String> toAddresses= new List<String>();
    
    //Set recipients
    for(integer i=0; i<locationList.size(); i++){
      for( Object_Champion__c oc :ocList){
        if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
          toAddresses.add (oc.Champion_email__c );
        }
      }
    }
    mail.setToAddresses(toAddresses);
    mail.setSenderDisplayName('RFT Auto Mail');
    mail.setTemplateId('00yyyyyyyyyyy');
    mail.setWhatId(rft.Id);
    mail.saveAsActivity = false;      
    mail.setTargetObjectId('00xxxxxxxxxxx');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  }        
}

 How can I solve this error?

 

Thanks in advance for your support!!!

 

Anna

  • March 05, 2013
  • Like
  • 0

Could someone help me?

 

I created the following trigger.

 

trigger RFTSetPDStatus on RFT_Category__c (before insert, before update) {
  if (Trigger.isInsert)
  { 
    for(RFT_Category__c pd:Trigger.new)
    {
        pd.PD_Status__c='Open';      
    }
  }
  if (Trigger.isUpdate)
  {
    Integer msExist=null;
    Integer msCnt=null;  
    for(RFT_Category__c pd:Trigger.new)
    {
        msExist=[SELECT COUNT() FROM Ichthys_RFT__c WHERE RFT_Category__r.Id = :pd.Id];
        if(msExist==0)
        {
          pd.PD_Status__c ='Open';
        }
        else
        {
          msCnt = [SELECT COUNT() FROM Ichthys_RFT__c WHERE RFT_Category__r.Id = :pd.Id AND Status__c <>'Completed'];
          if(msCnt==0)
          {
            pd.PD_Status__c ='Close';
          }
          else if(msCnt>0)
          {
            pd.PD_Status__c ='Open';
          }
        }
    }
  }
}

 

When I try to update over 1500 data from Apex Dataloader,

the error "System.LimitException: Too many SOQL queries: 101" occurred.

So I split data into 50 and updated them. 

Is there any way to update over 1500 data by changing this trigger code?

 

Thanks in advance for your support!

 

Anna

  • February 22, 2013
  • Like
  • 0

Please help me.

I'm creating a Trigger.

There are Object A and Object B.

Object B has a look up field of Object A.

What I want to do is when Object B is deleted, Object A's status is changed from "close" to "Open".

I created the following code, but the status of Object A isn't changed.

trigger SetStatus on ObjectB__c (before delete) {
  Set<Id> objId = new Set<Id>();
  list<ObjectA__c> objA = new list<ObjectA__c>();
  
  if (Trigger.isDelete)
  {
    for (ObjectB__c oldObjB : trigger.old)
    {
      objId.add(oldObjB.LookupField__c);
    }
    ObjectA__c objAList =[SELECT id, Status__c FROM ObjectA__c WHERE id in :objId ];
    if(objAList<>null){
      for(ObjectB__c objObjB : trigger.old)
      {
        objAList.Status__c = 'Open';
        objA.add(objAList);
      }
     if(objA.size()>0)
     {
     update objAList;
     }
   }
 }
}

Thanks in advance for your cooperation!!!

 

A.Tanaka

  • January 29, 2013
  • Like
  • 0

Is it possible to create New button in Lookup field?

 

Thanks,

Anna

  • June 23, 2011
  • Like
  • 0

I created save button.

If I click this button, the page jumps to Dashbords page.

How can I set page direction?

 

 

 

<apex:form >
<apex:commandButton action="{!save}" value="Save" id="theButton" /><br></br>

<body>

 

 

  • June 10, 2011
  • Like
  • 0

I'm creating editable table.

When I create lookup field, lookup button is not displayed.

 

My code is this.

 

 

<apex:page standardStylesheets="true" showHeader="True" sidebar="false" standardController="CR_CO__c" recordSetVar="crco"  > 
<style>
        .headerStyle{background-color:#0099FF;color:#000000}
        .dateStyle{width:250px}
</style>
<apex:form >
<apex:commandButton action="{!save}" value="Save" id="theButton"/>
<body>
<table border="2" >
<td><apex:inputField value="{!cro.Location__r.Name}"  />
</td>

</tr>
</apex:repeat>
</table>
</body>
</apex:form>
</apex:page>

 

 

  • June 09, 2011
  • Like
  • 0

Is it possible to divide header of datatable into two rows?

I know I can do this by using "table" but I want to use "datatable" because datatable is easy to set data.

I want to create as following image...

 

Anna

  • June 09, 2011
  • Like
  • 0

Hi all,

 

I created the following Visualforce Page. This page is shown when [Edit] button is clicked.

If there is an attachment, <apex:inputFile> is hidden. But if "Remove Attachfile" link is clicked, <apex:inputFile> will be shown.

 

The problem is that, when <apex:inputFile> is changed from "hidden" to "shown" and new attachment is attached and [Save] button is clicked, no attachment is attached...

 

I think it is Visualforce problem, especially "rendered" problem, because when <apex:inputFile> is originally shown, it works properly.

I can't solve this problem... Please help me...

 

<apex:page standardController="Sample__c" extensions="Sample_Ext">  
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockButtons location="top">
        <apex:commandButton value="Save" action="{!save}" />
        <apex:commandButton value="Cancel" action="{!Cancel}"/>
      </apex:pageBlockButtons>
      <apex:actionRegion >
        <apex:pageBlockSection title="Attachment Section" columns="3" id="BS1" >
          <apex:pageBlockSectionItem rendered="{!isAttached1}" dataStyle="width:10%">
            <apex:commandLink value="{!attachment1.Name}" action="{!downloadAttachment}" target="_blank" >
              <apex:param name="attachId" value="{!attachment1.Id}" />
            </apex:commandLink>
            <apex:commandLink value="[Remove Attachfile]" action="{!Remove}" onclick="if(!confirm('Are you sure?')){return false;}" reRender="BS1">
              <apex:param name="removeId" value="remove1" />
            </apex:commandLink>
          </apex:pageblocksectionitem>
          <apex:pageBlockSectionItem rendered="{!isAttached1==False}" dataStyle="width:10%">
            <apex:inputFile value="{!file1Content}" fileName="{!file1Name}"/>
          </apex:pageblocksectionitem>
        </apex:pageBlockSection>
      </apex:actionRegion>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

 Thanks in advance for your help.

 

Anna 

  • November 07, 2013
  • Like
  • 1

Please refer to the following code.

I'd like to use "objList" in Visualforce Page with some paging function

( for example, setCon.getHasPrevious(), setCon.getHasNext(), and so on...).

But I don't know how to set "objLIst" into ApexPages.StandardSetController.

I know I can set "rftList". but I need to use "objList".

 

A part of my code is this.

public with sharing class BulkAccept {

    // Inner Class Definition
    public Class RFT_Category_for_Select {        
        public Boolean checkAccept {get;set;}
        public Boolean checkNa {get;set;}
        public RFT_Category__c obj {get;set;}        
    }    

    // Property 
    public List<RFT_Category_for_Select> objList{get;set;}

    // Constructor
    public BulkAccept() {
        this.objList = new List<RFT_Category_for_Select>();  
        List<RFT_Category__c> rftList = [
            SELECT Id, Name 
              FROM RFT_Category__c 
             WHERE Reject__c = false
             ORDER BY Name
        ];
        for (RFT_Category__c rft : rftList) {
            RFT_Category_for_Select objItem = new RFT_Category_for_Select();
            objItem.checkAccept = false;
            objItem.checkNa     = false;
            objItem.obj         = rft;
            this.objList.add(objItem);
        }
        this.setCon = new ApexPages.StandardSetController(objList);
        this.setCon.setPageSize(50);     
    }

 Thanks in advance for your help.

 

Anna 

 

 

 

  • August 06, 2013
  • Like
  • 0

Please help me...

 

I have 20 E-mail fields named Email1__c, Email2__c, Email3__c,.....Email20__c.

What I want to do is loop thorugh these fields and input value.

 

Hereis my code.

Alerts__c alerts =new Alerts__c();
for(integer j=1;j==MailList.size();j++){
  String iStr = String.Valueof(j);
  String fieldname='Email'+iStr+'__c';
  alerts.get(fieldname)='test@test.com';
}

 But the following error occured.

 Expression cannot be assigned 

 

Please tell me how to solve this problem...

 

Thanks in advance for your help.

 

Anna

 

  • June 14, 2013
  • Like
  • 0

The following error occurrs but I don't know how to solve this.

 

MALFORMED_QUERY: childObj__r where Location__c = :tmpVar1) from ParentObj__c ^ ERROR at Row:1:Column:227 unexpected token: ':'

[Select r.Name,r.Id,
         (Select Status__c 
           From childObj__r 
          WHERE Location__c=:location )  
   From ParentObj__c r 
  where r.Location__c includes (:location) order by r.Name]));

 Thanks in advance for your help!

Anna

 

  • April 19, 2013
  • Like
  • 0

I'd like to show both parent and child objects in one table.

But I don't know how to show "Status__c" in VF page.

Please help me...

 

Here is my code.

 

  part of my Apex class.

setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
         [Select r.Phase__c, r.Name, 
                 r.Item_No_seq__c, r.Id,
                 (Select Status__c From Ichthys_RFT__r)  
            From RFT_Category__c r 
           where r.Location__c includes (:location) order by r.Item_No_seq__c]));

 my VF page.

 If I try to save this code, the error occurrs. "Error: Unknown property 'VisualforceArrayList.Status__c'"

<apex:pageBlockTable id="block" value="{!lstREFCategory}" var="rftObject" style="width:100%" >
  <apex:column headerValue="No" >
  <apex:Outputtext value="{0,number,###,###,###,###}">
  <apex:param value="{!rftObject.Item_No_seq__c}"></apex:param>
  </apex:outputtext>
  </apex:column>
  <apex:column style="width:200px"  >
    <apex:facet name="header">
        Phase
    </apex:facet>
    <apex:Outputtext value="{!rftObject.Phase__c}" style="width:50px" />
  </apex:column>
  <apex:column headerValue="Status">
  <apex:Outputtext value="{!rftObject.Ichthys_RFT__r.Status__c}" style="width:200px"/>
  </apex:column>
</apex:pageBlockTable>

 Thank you,

 Anna

  • April 15, 2013
  • Like
  • 0

When I update data, the following trigger can't get "Item_No_seq__c" value.

Please tell me what is a problem...

 

trigger IchthysRFT on RFT_Category__c (before insert, before update) {
  Map<String,Map<Double,RFT_Category__c>> rft =
    new Map<String,Map<Double,RFT_Category__c>>();
  
  Set<String> objNos = new Set<String>();
  Set<Double> itemSeq = new Set<Double>();
  for(RFT_Category__c record:trigger.new) {
    objNos.add(record.Object_No__c);
    itemSeq.add(record.Item_No_seq__c);
  }
  for(RFT_Category__c record:[SELECT Id, Item_No_seq__c, Object_No__c
                                FROM RFT_Category__c
                               WHERE Object_No__c IN :objNos AND Item_No_seq__c!=null 
                               ORDER BY Item_No_seq__c DESC limit 1]) {
    if(!rft.containsKey(record.Object_No__c)) {
      rft.put(record.Object_No__c,new Map<Double,RFT_Category__c>());
    }
    rft.get(record.Object_No__c).put(record.Item_No_seq__c,record);
  }
  for(RFT_Category__c record:Trigger.new) {
    if(rft.containsKey(record.Object_No__c)&& rft.get(record.Object_No__c).containsKey(record.Item_No_seq__c)) {
      RFT_Category__c tmp = rft.get(record.Object_No__c).get(record.Item_No_seq__c);
      if(Trigger.isUpdate){
        RFT_Category__c oldpd=Trigger.oldMap.get(record.id);
        if(record.Object_No__c!= oldpd.Object_No__c){
          record.Item_No_seq__c = tmp.Item_No_seq__c +1;
        }
      }
    }else {
      record.Item_No_seq__c = 1;
    }
  }
}

 

Thank you,

Anna

  • March 28, 2013
  • Like
  • 0

When I update one record, this trigger works, but when I update multiple records by using Apex Dataloader, it doesn't work.

This trigger updates parent object when its child object's status is updated.

 

1. Child object Trigger: it just updates parent object.

trigger RFTSetPDStatusFromMS on Ichthys_RFT__c(after insert, after update) {
    
  if (Trigger.isInsert||Trigger.isUpdate)
  {
    list<Ichthys_RFT__c>msl=[SELECT id,Status__c,RFT_Category__r.Id FROM Ichthys_RFT__c WHERE Id in :Trigger.new];
    Ichthys_RFT__c newMs=null;
    if(msl.size()>0)
    {
      newMs=msl[0]; 
      RFT_Category__c[] pdList = [SELECT id, Name, PD_Status__c FROM RFT_Category__c WHERE Id = :newMs.RFT_Category__r.Id];
      if(pdList.size()>0)
      {
        update pdList[0];
      }
    }
  }
}

2. Parent Object Trigger: it checks child object status and update parent status.

trigger RFTSetPDStatus on RFT_Category__c (before update) {
  if (Trigger.isUpdate)
  {
    List<Ichthys_RFT__c > msList= [SELECT RFT_Category__r.Id,Status__c FROM Ichthys_RFT__c WHERE RFT_Category__r.Id in :Trigger.new];
    Integer msExist=0;
    Integer msCnt=0;  

    if(msList.size()>0){
      msExist +=1;
    }
    for(RFT_Category__c pd:Trigger.new){
      if(msExist==0){
        pd.PD_Status__c ='Open';
      }else{
        for( Ichthys_RFT__c ms :msList){
          if( ms.RFT_Category__r.Id == pd.Id && ms.Status__c <>'Completed' &&  ms.Status__c <>'Not Applicable'){
            msCnt +=1;
          }
        }
        if(msCnt==0){
          pd.PD_Status__c ='Close';
        }
        else if(msCnt>0){
          pd.PD_Status__c ='Open';
        }
      }
    }
  }
}

 Thanks in advance for your help.

 

Anna

 

  • March 26, 2013
  • Like
  • 0

When I use apex dataloader to insert multiple data, the following error occurres.

"System.LimitException: Too many code statements: 200001"

Is it because I use List ?

trigger RFTSetPDStatus on RFT_Category__c (before insert, before update) {
 List<Ichthys_RFT__c > msList= [SELECT RFT_Category__r.Id,Status__c FROM Ichthys_RFT__c ];
  if (Trigger.isInsert)
  { 
    for(RFT_Category__c pd:Trigger.new)
    {
        pd.PD_Status__c='Open';      
    }
  }
  else if (Trigger.isUpdate)
  {
    Integer msExist=0;
    Integer msCnt=0;  
    for(RFT_Category__c pd:Trigger.new)
    {
      for( Ichthys_RFT__c ms :msList){
        if( ms.RFT_Category__r.Id == pd.Id ){
          msExist +=1;
        }
      }
      if(msExist==0)
      {
        pd.PD_Status__c ='Open';
      }
      else
      {
        for( Ichthys_RFT__c ms :msList){
          if( ms.RFT_Category__r.Id == pd.Id && ms.Status__c <>'Completed' &&  ms.Status__c <>'Not Applicable'){
            msCnt +=1;
          }
        }
          if(msCnt==0)
          {
            pd.PD_Status__c ='Close';
          }
          else if(msCnt>0)
          {
            pd.PD_Status__c ='Open';
          }
        }
    }
  }
}

Thank you,

Anna

  • March 26, 2013
  • Like
  • 0

Please help me...

 

When I insert or update data, the following trigger sends email.

This trigger works when insert or update one data.

But when I try to insert or update multiple data by Apex Data Loader, error occurs.

How can I solve this error?

 

<error>

PDSendEmailtoOC: execution of AfterUpdate
caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []
Trigger.PDSendEmailtoOC: line 161, column 1
 
trigger PDSendEmailtoOC on RFT_Category__c (after insert,after update) {

  List<RFT_Category__c > pdList= [SELECT Location__c,Object_No__c FROM RFT_Category__c ];
  List<Object_Champion__c> ocList=[SELECT Location__c,Object_No__c,Champion_email__c FROM Object_Champion__c];
  List<AreaCoordinators__c> acList=[SELECT Area__c, Group_Mail_Address__c FROM AreaCoordinators__c];
  String recipient = '';
  List<String> toAddresses= new List<String>();
  List<String> ccAddress = new List<String>();
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  
  for (RFT_Category__c rft : Trigger.new) {
  
    //Rejectの場合、InitiatorにMail
    if(rft.Reject__c==TRUE && rft.E_mail_Address__c<>null){
      //更新前のデータのRejectがFalseの場合のみ送信
      if(trigger.oldMap.get(rft.id).Reject__c==FALSE){
        recipient = rft.E_mail_Address__c;
      
        //一時的にContactを作成。setTargetObjectIdでContactを指定しないとsetWhatIDでCustomObjectを指定できないため。
        Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
        insert tempContact;

        toAddresses.add(rft.E_mail_Address__c);
        mail.setSenderDisplayName('RFT Auto Mail');
        mail.setTemplateId('00XN0000000DbBw');
        mail.saveAsActivity = false;
        mail.setTargetObjectId(tempContact.id);
        mail.setWhatId(rft.Id); 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      
        //Contact削除
        delete tempContact;
      }
    }else if(rft.Location__c<>null && rft.Object_No__c<>null){
    //Rejectでない場合、割り振られたLocationのArea CoordinatorとObjective Champion、InitiatorにMail。変更がない場合はなにもしない。
  
      String [] locationList = rft.Location__c.split(';');
  
      //ObjectNoが異なる場合。
    
      if(Trigger.isUpdate){
        if(trigger.oldMap.get(rft.id).Object_No__c==null || trigger.oldMap.get(rft.id).Object_No__c<>rft.Object_No__c){

          //Set recipients
          for(integer i=0; i<locationList.size(); i++){
        
            //Object Championの宛先設定
            for( Object_Champion__c oc :ocList){
              if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
                String [] OCMailList = oc.Champion_email__c.split(';');
                for(integer j=0; j< OCMailList.size(); j++){
                  if(i==0&&j==0){
                    recipient=OCMailList[j];
                  }else{
                    toAddresses.add (OCMailList[j]);
                  }
                }
              }             
            }
            //Area Coordinatorの宛先設定
            for(AreaCoordinators__c ac :acList){
              if(ac.Area__c == locationList[i]){
                String [] ACMailList = ac.Group_Mail_Address__c .split(';');
                for(integer m=0; m< ACMailList .size(); m++){
                  toAddresses.add (ACMailList[m]);
                }
              }
            }
          } 
          Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
          insert tempContact;
          if(rft.E_mail_Address__c<>null){
            ccAddress.add(rft.E_mail_Address__c);
            mail.setCcAddresses(ccAddress);
          }
          mail.setTargetObjectId(tempContact.id);
          mail.setToAddresses(toAddresses);
          mail.setSenderDisplayName('RFT Auto Mail');
          mail.setTemplateId('00XN0000000DbB3');
          mail.saveAsActivity = false;
          mail.setWhatId(rft.Id);
          Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
          delete tempContact;
    
        //ロケーションが異なる場合。
        }else if(trigger.oldMap.get(rft.id).Location__c<>rft.Location__c) {
        
          //古いデータのLocationが空の場合
          if(trigger.oldMap.get(rft.id).Location__c==null){
            for(integer i=0; i<locationList.size();i++){
              for( Object_Champion__c oc :ocList){
                if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
                  String [] OCMailList = oc.Champion_email__c.split(';');
                  for(integer k=0; k< OCMailList.size(); k++){
                    if(recipient==''){ 
                      recipient=OCMailList[k];
                    }else{
                      toAddresses.add (OCMailList[k]);
                    }
                  }
                }             
              }
              //Area Coordinatorの宛先設定
              for(AreaCoordinators__c ac :acList){
                if(ac.Area__c == locationList[i]){
                  String [] ACMailList = ac.Group_Mail_Address__c .split(';');
                  for(integer m=0; m< ACMailList .size(); m++){
                    toAddresses.add (ACMailList[m]);
                  }
                }
              }
            }
          }else{   //古いデータのLocationが空でない場合
            String [] oldLocationList = trigger.oldMap.get(rft.id).Location__c.split(';');
            for(integer i=0; i<locationList.size();i++){
              integer cnt = 0;
              for(integer j=0; j<oldLocationList .size(); j++){
                if(LocationList[i]==oldLocationList[j]){
                  cnt=cnt+1;
                }
              }
              if(cnt==0){ //locationList[i]の宛先設定
                //Object Championの宛先設定
               for( Object_Champion__c oc :ocList){
                  if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
                    String [] OCMailList = oc.Champion_email__c.split(';');
                    for(integer k=0; k< OCMailList.size(); k++){
                      if(recipient==''){
                        recipient=OCMailList[k];
                      }else{
                        toAddresses.add (OCMailList[k]);
                      }
                    }
                  }             
                }
                //Area Coordinatorの宛先設定
                for(AreaCoordinators__c ac :acList){
                  if(ac.Area__c == locationList[i]){
                    String [] ACMailList = ac.Group_Mail_Address__c .split(';');
                    for(integer m=0; m< ACMailList .size(); m++){
                      toAddresses.add (ACMailList[m]);
                    }
                  }
                }  
              }       
            }
          } 
          if(recipient<>''){
            Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
            insert tempContact;
            if(rft.E_mail_Address__c<>null){
              ccAddress.add(rft.E_mail_Address__c);
              mail.setCcAddresses(ccAddress);
            }
            mail.setTargetObjectId(tempContact.id);
            mail.setToAddresses(toAddresses);
            mail.setSenderDisplayName('RFT Auto Mail');
            mail.setTemplateId('00XN0000000DbB3');
            mail.saveAsActivity = false;
            mail.setWhatId(rft.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            delete tempContact;     
          }
        }
      }else if(Trigger.isInsert){
        //Set recipients
        for(integer i=0; i<locationList.size(); i++){
        
          //Object Championの宛先設定
          for( Object_Champion__c oc :ocList){
            if( oc.Location__c == locationList[i] && oc.Object_No__c ==rft.Object_No__c ){
              String [] OCMailList = oc.Champion_email__c.split(';');
              for(integer j=0; j< OCMailList.size(); j++){
                if(i==0&&j==0){
                  recipient=OCMailList[j];
                }else{
                  toAddresses.add (OCMailList[j]);
                }
              }
            }             
          }
          //Area Coordinatorの宛先設定
          for(AreaCoordinators__c ac :acList){
            if(ac.Area__c == locationList[i]){
              String [] ACMailList = ac.Group_Mail_Address__c .split(';');
              for(integer m=0; m< ACMailList .size(); m++){
                toAddresses.add (ACMailList[m]);
              }
            }
          }
        } 
        Contact tempContact = new Contact(email = recipient , firstName = 'RFT', lastName = 'Temp');
        insert tempContact;
        if(rft.E_mail_Address__c<>null){
          ccAddress.add(rft.E_mail_Address__c);
          mail.setCcAddresses(ccAddress);
        }
        mail.setTargetObjectId(tempContact.id);
        mail.setToAddresses(toAddresses);
        
        mail.setSenderDisplayName('RFT Auto Mail');
        mail.setTemplateId('00XN0000000DbB3');
        mail.saveAsActivity = false;
        mail.setWhatId(rft.Id);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        delete tempContact;
      } 
    }
  }
}

 

Thanks in advance for your help!!

 

Anna

  • March 08, 2013
  • Like
  • 0