• Avaneesh
  • NEWBIE
  • 369 Points
  • Member since 2017
  • Salesforce Developer
  • Astrea it Services

  • Chatter
    Feed
  • 12
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 113
    Replies
Hi,

Below is the code of custom Setting Data with the sorting the values in the pageBlockTable,
Sort order is not working, Below is my code.
Please can anyone help me,

<apex:page controller="CustomSettingsCon">
    <apex:form>
        <apex:pageBlock id="pageBlock">
             <apex:pageBlockButtons location="top">
      <apex:commandButton value="View" action="{!ViewData}" id="theButton" rerender="pageBlock"></apex:commandButton>
    </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!codes}" var="c" rendered="{!NOT(ISNULL(codes))}" >
             <apex:column >
         <apex:facet name="header">   
           <apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
                <apex:outputLink value="/{!c.Id}" target="_blank">{!c.Name}</apex:outputLink>
       </apex:column>
             <apex:column value="{!c.Phone_Number__c}">
         <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Phone_Number__c{!IF(sortExpression=='Phone_Number__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Phone_Number" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
               <apex:column value="{!c.Address__c}">
          <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Address__c{!IF(sortExpression=='Address__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Address" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
                 <apex:column value="{!c.Email__c}">
          <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Email__c{!IF(sortExpression=='Email__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Email__c" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
===============
public class CustomSettingsCon {
    public List<Account__c> codes{get;set;}
        private String sortDirection = 'ASC';
   private String sortExp = 'name';
   
    public String sortExpression{
   
     get
     {
        return sortExp;
     }
     set
     {
       //if the column is clicked on then switch between Ascending and Descending modes
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }
    
    public String getSortDirection()
 {
    //if not column is selected
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }
    
    public void setSortDirection(String value){
   
   sortDirection = value;
 }
 
   public List<Account__c> getcodes(){
       return codes;
   }

    
    public void ViewData(){
           string sortFullExp = sortExpression  + ' ' + sortDirection;
        
       Map<String,Account__c> allcodes = Account__c.getAll();
       codes = allCodes.values();  
    }
}

Thanks,
Varalaxmi
Hi Every one,
I want to write a trigger to update record for unrelated object. So that i written one trigger it showing error can any one help me out.

trigger populateExpenseFromUser on Expense__c (before insert , before update)
{
    
    Set<ID> setExpIds = new Set<ID>();
    for(Expense__c exp : trigger.new){
        if(exp.Claim_Purpose__c!= null)
        setExpIds.add(exp.Claim_Purpose__c);
    }
    
     MAP<ID , User> mapExp = new MAP<ID , User>([Select Id,Branch__c,Department__c,Designation__c from user where id in: setExpIds]);
     for(Expense__c exp : trigger.new)
       {
        if(exp.Claim_Purpose__c != null)
          {
            User tr = mapExp.get(exp.Claim_Purpose__c);
            exp.Branch__c= tr.Branch__c;
            exp.Department__c= tr.Department__c;
            exp.Designation__c=tr.Designation__c;
          //  update exp;
            
          }
       
       }
Hi everyone,

Can anyone help me to write a trigger to create an Contact when an Account is created and send an email notification to the contact. In Account object I have created a custom field for email ID and create a contact.

Thanks in advance.

Regards,
naga.
Hi Team,

Can any one please help me to create if contract enddate is changed manually then new opportunity needs to be create which is assosciate to lookup account on contract object.

Thanks

 
Hi Everyone

I need to relate two standard objects (Lead and Event) for whatever reason. Everytime a record is changed in Lead, it has to change in Event. But in both ways, I mean, from Lead to Event and from Event to Lead.

it is simple by doing it in one way , I have a trigger (working fine) that update a Event record everytime a record is changed in Lead. But, and here comes the question, how do I do the update in both directions?

I thought doing it with another trigger but it would be an infinite loop. Once the trigger on Lead updates the record in Event, the trigger on event would fire and so on...

Anyone can help me?

Thanks in advance for your time
Cheers!!
Alberto
  1. Account ==== Contact   on contact Status__C field is there (Total 10 records)
If one record status is changed to Approved then ‘Remaining 9 records status__c would be changed to Declined ’ . But first Record Status__c  would be Same(Approved).
How can we achieve this through?
1.trigger
2. Process Builder
  1. Account ==== Contact   on contact Status__C field is there (Total 10 records)
I have 2 custom objects employee__c and company__c.In employee  Object I have a field called salry__c and in Company object Ihave a field max_salry__c .I want to populate max salary of the employees on Parent Object Field max_salry__c.Please help me on trigger for this scenario.

Here is the snippet I tried .

trigger calculateMaxSalary on Employee__c (after update, after insert) {

        /*Map<Id, Compny__c> parentcomp = new Map<Id, Compny__c>();
        List<Id> listIds = new List<Id>();

        for(Employee__c childObj : Trigger.new) {
            listIds.add(childObj.salaries__c);
        }

        parentcomp= new Map<Id, Compny__c> ([Select Id, Name,max_salary__c, (Select Id, salry__c from Emploies__r) from Compny__c where Id in :listIds]);

        for(Employee__c emp : Trigger.new) {    
            Compny__c comp = parentcomp.get(emp.salaries__c);
            system.debug('Max Salary#########'+comp.max_salary__c);
            system.debug('Salary**************'+emp.salry__c);
            //comp.max_salary__c= max(emp.salry__c);
        }

        update parentcomp.values();
        */
        
        
               
  // }
public class Prime {
    Integer i,num;
    public void entnum(Integer n){
        num = n;
        for (i=2;   i<=num; i++){
            if (system.math.mod(num,i) == 0){
                System.debug('Number is not Prime');
                break;
            }
                if(i == num) {
                  system.debug('Number is  Prime');  
               
                } 
            }
        }
       }
Hi all,

I have some custom object and I want to capture the number of attachments attached to that particular record. Please help me how to achieve this.

Thanks in Advance
I want to send emails from apex, I'm using Visualforce email templates. This is my code:
 
EmailTemplate templateId = [Select id from EmailTemplate where DeveloperName = 'User_Template'];
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress LIMIT 1];

               	
for(User usr: users) {
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

    if ( owea.size() > 0 ) {
        email.setOrgWideEmailAddressId(owea.get(0).Id);
    }
			
    email.setSaveAsActivity(false);
    email.setSubject('Test Subject');			
    email.setTargetObjectId(usr.Id);
    email.setTemplateID(templateId.Id); 

    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });  
}

Email template:
<messaging:emailTemplate subject="Test" recipientType="User">
	<messaging:htmlEmailBody >
		this is a test
	</messaging:htmlEmailBody>
</messaging:emailTemplate>



It's sending the email but the body is empty. 

When sending from setup and using "Send Test and Verify Merge Fields" - it works - body is sent.

I've tried this: Sending Emails in Salesforce to Non-Contacts Using Apex . It throws an error a null reference error, I've checked in the log and the emailBody is null.

I've tried setting email.setWhatId(usr.Id);  - no change

The only solution that worked was building the message as string in apex and using email.setHtmlBody(someString);

However I'm curious of why using the template doesn't work, any help would be highly appreciated.

Hi all,
I builded a Portal community and I need to permit Customers to upload files in "Note and Attachment" of Cases, but NOT in the other objects.

I can't just hide them from page layout because I need to let Customer download them, just not the upload.
How can i fulfill the requirements?
I tried with a trigger on Attachment but it didn't work

Thanks

Hi,

Below is the code of custom Setting Data with the sorting the values in the pageBlockTable,
Sort order is not working, Below is my code.
Please can anyone help me,

<apex:page controller="CustomSettingsCon">
    <apex:form>
        <apex:pageBlock id="pageBlock">
             <apex:pageBlockButtons location="top">
      <apex:commandButton value="View" action="{!ViewData}" id="theButton" rerender="pageBlock"></apex:commandButton>
    </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!codes}" var="c" rendered="{!NOT(ISNULL(codes))}" >
             <apex:column >
         <apex:facet name="header">   
           <apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
                <apex:outputLink value="/{!c.Id}" target="_blank">{!c.Name}</apex:outputLink>
       </apex:column>
             <apex:column value="{!c.Phone_Number__c}">
         <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Phone_Number__c{!IF(sortExpression=='Phone_Number__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Phone_Number" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
               <apex:column value="{!c.Address__c}">
          <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Address__c{!IF(sortExpression=='Address__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Address" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
                 <apex:column value="{!c.Email__c}">
          <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Email__c{!IF(sortExpression=='Email__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Email__c" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
===============
public class CustomSettingsCon {
    public List<Account__c> codes{get;set;}
        private String sortDirection = 'ASC';
   private String sortExp = 'name';
   
    public String sortExpression{
   
     get
     {
        return sortExp;
     }
     set
     {
       //if the column is clicked on then switch between Ascending and Descending modes
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }
    
    public String getSortDirection()
 {
    //if not column is selected
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }
    
    public void setSortDirection(String value){
   
   sortDirection = value;
 }
 
   public List<Account__c> getcodes(){
       return codes;
   }

    
    public void ViewData(){
           string sortFullExp = sortExpression  + ' ' + sortDirection;
        
       Map<String,Account__c> allcodes = Account__c.getAll();
       codes = allCodes.values();  
    }
}

Thanks,
Varalaxmi
Hi,
How can i learn Apex? I know nothing about it but feel like improving my skills in developing. 
Any books?Videos?Courses? (Will courses help me or is it a "waste of money"?)
Hi All,
In my current scenario 
I am having two Object
1. projects__c(Parent object) (In Project object having field ProjectTaskDescription__c, TimesheetStartDate__c, TimesheetEndDate__c  ) 
2. Timesheet__c(Child Object) (In Timesheet object having field  TimesheetDescription__c, Timesheet_Date__c   )

Now  I want to write a trigger on the Parent object(Projects__c) when user will update TimesheetStartDate, TimesheetEndDate and once he will save then related timesheet object(Timesheet_Date__c) field date is between  Project(TimesheetStartDate, TimesheetEndDate )   then  (TimesheetDescription__c ) field  value need to concatenate and display into project object field ( ProjectTaskDescription__c ) ..

Please help me how to write trigger for this.
Please help me to write a trigger on this scenario.


Thanks in Advance.
 
 
Hi All,

I want to remove white spaces from the given string. How to achieve this using the regular expression.

Example:
Salesforce Developer ==> I want to convert the string to like this "SalesforceDeveloper". Remove all white spaces from the given string.

Thanks,
Vijay
 
Hi Every one,
I want to write a trigger to update record for unrelated object. So that i written one trigger it showing error can any one help me out.

trigger populateExpenseFromUser on Expense__c (before insert , before update)
{
    
    Set<ID> setExpIds = new Set<ID>();
    for(Expense__c exp : trigger.new){
        if(exp.Claim_Purpose__c!= null)
        setExpIds.add(exp.Claim_Purpose__c);
    }
    
     MAP<ID , User> mapExp = new MAP<ID , User>([Select Id,Branch__c,Department__c,Designation__c from user where id in: setExpIds]);
     for(Expense__c exp : trigger.new)
       {
        if(exp.Claim_Purpose__c != null)
          {
            User tr = mapExp.get(exp.Claim_Purpose__c);
            exp.Branch__c= tr.Branch__c;
            exp.Department__c= tr.Department__c;
            exp.Designation__c=tr.Designation__c;
          //  update exp;
            
          }
       
       }
Hi All,

I have a requirement in which account status should be updated if its all related contacts have same status. I have three status values in contact, 'New', 'In progress' and 'Cancelled'. Suppose an account A has three related contacts C1, C2 & C3. If the status of all three contacts is 'New', then account's status should be 'New'. Can anyone help me out on this? 

Regards,
Raksha
I have the below trigger to create Person Account when a new record is created in a custom object Student__c

I would like to seek some expert help on how to modify the trigger to have 'after update' if the record on Student__c is modified, the changes also should be done on the corresponding person account.

The external ID field on Student__c is Student_id__c and also unique field is NRIC__c. I also store the Id from Student__c into Person Account (Student_Id_from_Student_Prospects__pc,NRIC_PC, Salesforce_Id_from_Student_Object__pc

Please help to modify the below trigger to have 'after insert' and 'after update'
-------------------
trigger CreatePersonAccountfromStudent on Student__c (after insert)
{
    List<account> acc=new List<account>();
    Map<Id, String> m = new Map<Id, String>();
    RecordType rt = [select id from RecordType where SobjectType='Account' and Name='Student' Limit 1];
    for(student__c stud:Trigger.New)
    {
      acc.add(new account(
        Autocreated__pc=True,
        Block__pc=Stud.Block__c,
        Bulk_Load__pc=Stud.Bulk_Load__c,
        Current_Acedamic_Year__pc=Stud.Current_Acedamic_Year__c,
        Date_of_Collection__pc=Stud.Date_of_Collection__c,
        Discount_Percentage__pc=Stud.Discount_Percentage__c,
        Discount_Policy__pc=Stud.Discount_Policy__c,
        Discount_Remarks__pc=Stud.Discount_Remarks__c,
        Discount_Type__pc=Stud.Discount_Type__c,
        English__pc=Stud.English__c,
        Event_Name__pc=Stud.Event_Name__c,
        Exclude_Registration__pc=Stud.Exclude_Registration__c,
        Father_Email__pc=Stud.Father_Email__c,
        Father_Name__pc=Stud.Father_Name__c,
        Father_NRIC__pc=Stud.Father_NRIC__c,
        Father_Office_Phone__pc=Stud.Father_Office_Phone__c,
        Father_Primary_Contact__pc=Stud.Father_Primary_Contact__c,
        Father_Remark__pc=Stud.Father_Remark__c,
        Father_Staff__pc=Stud.Father_Staff__c,
        Gender__pc=Stud.Gender__c,
        GEP__pc=Stud.GEP__c,
        Guardian_Email__pc=Stud.Guardian_Email__c,
        Guardian_Mobile__pc=Stud.Guardian_Mobile__c,
        Guardian_Name__pc=Stud.Guardian_Name__c,
        Guardian_NRIC__pc=Stud.Guardian_NRIC__c,
        Guardian_Office_Phone__pc=Stud.Guardian_Office_Phone__c,
        Guardian_Primary_Contact__pc=Stud.Guardian_Primary_Contact__c,
        Guardian_Relationship__pc=Stud.Guardian_Relationship__c,
        Guardian_Remarks__pc=Stud.Guardian_Remark__c,
        Guardian_Staff__pc=Stud.Guardian_Staff__c,
        How_did_you_hear_about_us__pc=Stud.How_did_you_hear_about_us__c,
        Is_Mind_Stretcher_Staff_Mother__pc=Stud.Is_Mind_Stretcher_Staff_Mother__c,
        LastName=Stud.name__c,
        Level__pc=Stud.Level__c,
        Level_Promoted_DateTime__pc=Stud.Level_Promoted_DateTime__c,
        Maths__pc=Stud.Maths__c,
        Mobile_No_Father__pc=Stud.Mobile_No_Father__c,
        Mother_Email__pc=Stud.Mother_Email__c,
        Mother_Name__pc=Stud.Mother_Name__c,
        Mother_No_Mobile__pc=Stud.Mobile_No_Mother__c,
        Mother_NRIC__pc=Stud.Mother_NRIC__c,
        Mother_Office_Phone__pc=Stud.Mother_Office_Phone__c,
        Mother_Primary_Contact__pc=Stud.Mother_Primary_Contact__c,
        Mother_Remark__pc=Stud.Mother_Remark__c,
        Mother_Staff__pc=Stud.Mother_Staff__c,
        MS_Start_Kit_Bag__pc=Stud.MS_Start_Kit_Bag__c,
        Nationality__pc=Stud.Nationality__c,
        NRIC__pc=Stud.NRIC__c,
        NTUC_10_Discount__pc=Stud.NTUC_10_Discount__c,
        NTUC_Card_Expiry__pc=Stud.NTUC_Card_Expiry__c,
        NTUC_Remark__pc=Stud.NTUC_Remark__c,
        Others__pc=Stud.Others__c,
        Others_How_did_you_hear_about_us__pc=Stud.Others_How_did_you_hear_about_us__c,
        Person_Contact__pc=Stud.Person_Contact__c,
        PersonBirthdate=Stud.DOB__c,
        PersonHomePhone=Stud.Home_No__c,
        PersonMailingPostalCode=Stud.Postal_Code__c,
        PersonMailingStreet=Stud.Street_Temp__C,
        Primary_Contact_Number__pc=Stud.Contact_number__c,
        Primary_Email__pc=Stud.Primary_Email__c,
        Primary_Name__pc=Stud.Primary_Name__c,
        Primary_Remark__pc=Stud.Primary_Remark__c,
        Promotion__pc=Stud.Promotion__c,
        Reading_Oceans_Email__pc=Stud.Reading_Oceans_Email__c,
        Reading_Oceans_End_Date__pc=Stud.Reading_Oceans_End_Date__c,
        Reading_Oceans_Start_Date__pc=Stud.Reading_Oceans_Start_Date__c,
        Reading_Oceans_Subscrip__pc=Stud.Reading_Oceans_Subscrip__c,
        recordtypeid=rt.id,
        Registration_Centre__pc=Stud.Registration_Centre__c,
        Related_Centres__pc=Stud.Related_Centres__c,
        Remarks__pc=Stud.Remarks__c,
        RO_Date_Send_User__pc=Stud.RO_Date_Send_User__c,
        RO_Remark__pc=Stud.RO_Remark__c,
        RO_Type__pc=Stud.RO_Type__c,
        Safra_Card_Expiry__pc=Stud.Safra_Card_Expiry__c,
        Safra_Card_Holding__pc=Stud.Safra_Card_Holding__c,
        Safra_Remark__pc=Stud.Safra_Remark__c,
        Salesforce_Id_from_Student_Object__pc=Stud.ID,
        School__pc=Stud.School__c,
        Science__pc=Stud.Science__c,
        Secondary_Stream__pc=Stud.Secondary_Stream__c,
        Start_Date__pc=Stud.Start_Date__c,
        Street__pc=Stud.Street__c,
        Student_Id_from_Student_Prospects__pc=Stud.name,
        Student_Old_Reference_ID__pc=Stud.Student_Old_Reference_ID__c,
        Student_Status__pc=Stud.Student_Status__c,
        Student_Type__pc='Student',
        Tick_to_activate_inter_branch_discount__pc=Stud.Tick_to_activate_inter_branch_discount__c,
        Type_Course_Fee__pc=Stud.Type_Course_Fee__c,
        Unit_Number__pc=Stud.Unit_Number__c
    ));
 }
    insert acc;
}
  • July 24, 2017
  • Like
  • 0