• sooraj kesavadas
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 8
    Replies
I have four multi select picklists inside the contact object and I am trying to display them to the community user so that they can select as needed. The vf page I have used is:
<apex:page standardcontroller="contact" showheader="false" extensions="ContactEditpageController">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script> $j = jQuery.noConflict();</script>
<apex:form >
    <apex:pageBlock id="pb1" mode="edit">
        <apex:pageBlockButtons >  
            <apex:commandButton action="{!save}"  value="Save"/> 
        </apex:pageBlockButtons>
        <apex:pageMessages />
        <apex:pageBlockSection title="Edit Address" columns="2">
            <apex:inputField value="{!myContact.MailingStreet}"/>
            <apex:inputField value="{!myContact.MailingCity}"/>
            <apex:inputField value="{!myContact.MailingState}"/>
            <apex:inputField value="{!myContact.MailingPostalCode}"/>
            <apex:inputField value="{!myContact.MailingCountry}"/> 
        </apex:pageBlockSection> 
        <apex:pageBlockSection title="Interest" columns="1">
            <apex:inputField value="{!myContact.News__c}"/>
            <apex:inputField value="{!myContact.Research__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

and my controller is:
 
public with sharing class ContactEditpageController {
public contact myContact { get; set; }
public ContactEditpageController(ApexPages.StandardController controller) {
    user loggdinUserRecord=[select ContactId from user where id=:userinfo.getuserid()];            
    myContact=[select id,email,MobilePhone,account.id,News__c,Research__c,HomePhone,FirstName,LastName,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry  from contact where id =:loggdinUserRecord.contactid];
}            
public pagereference save(){
    PageReference pageRef = new PageReference('/apex/ContactEditPage');
    try{
        update myContact;
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Contact detail updated.Thank you!'));        
    }catch(exception e){
        ApexPages.addMessages(e);
        pageRef=null;
    }   
    return pageRef;}}

The fields are displaying in the correct fashion but out of two pick lists I have queried, I can only see one of them in the community and even that partially. What am I doing wrong in displaying the pick lists? This is the picture of my community page:


User-added image

Any advice is very much appreciated.Thank you!
I have a user case where the community user needs to see all the appointments of all the contacts from their parent account.Here is the Code I have:
 
public class AppointmentListController {

public String AppFilterId {get; set;}
private Integer pageSize = 10;
private String baseQuery ='SELECT Name, contact.name, Status__c FROM appointment__c WHERE contact IN (SELECT Id FROM Contact WHERE AccountId = :myContact.AccountId)';

public AppointmentListController(){
    Contact myContact=[select id,accountid from contact where id in(select contactId from user where id=:userinfo.getuserid())];
}

public ApexPages.StandardSetController AppSetController {
    get{
        if(AppSetController == null){
            AppSetController = new ApexPages.StandardSetController(Database.getQueryLocator(baseQuery));
            AppSetController.setPageSize(pageSize);
            if(AppFilterId != null)
            {
                AppSetController.setFilterId(AppFilterId);
            }
        }
        return AppSetController;
    }set;
}

public AppointmentListController(ApexPages.StandardSetController c) {   }

public void firstPage()
{
    AppSetController.first();
}

public void lastPage()
{
    AppSetController.last();
}

public void next()
{
    if(AppSetController.getHasNext())
    {
        AppSetController.next();
    }
}

public void prev()
{
    if(AppSetController.getHasPrevious())
    {
        AppSetController.previous();
    }
}

public List<appointment__c> getAppoinments()
{
    return (List<appointment__c>)AppSetController.getRecords();
}

public SelectOption[] getAppoinmentExistingViews(){
    return AppSetController.getListViewOptions();
}

public PageReference resetFilter()
{
    AppSetController = null;
    AppSetController.setPageNumber(1);
    return null;
}}

and this is my visualforce page:
 
<apex:page controller="AppointmentListController" sidebar="false" showHeader="false">

<apex:form id="pageForm">

   <apex:actionStatus id="ajaxStatus" startText="Loading..."  stopText=""/>
    <br/><br/>

 <apex:pageBlock title="Appoinments">
    <apex:pageBlockButtons >
            <apex:commandButton action="{!firstPage}" value="|<<" reRender="AppTable"  status="ajaxStatus" />
            <apex:commandButton action="{!prev}" value="Prev" reRender="AppTable"  status="ajaxStatus" />
            <apex:commandButton action="{!next}" value="Next" reRender="AppTable"  status="ajaxStatus" />
            <apex:commandButton action="{!lastPage}" value=">>|" reRender="AppTable"  status="ajaxStatus" />
        </apex:pageBlockButtons>

     <apex:pageBlockTable value="{!Appoinments}" var="item" id="AppTable">
         <apex:column value="{!item.name}" headerValue="Appoinment Name"/>
         <apex:column value="{!item.Status__c}" headerValue="Status"/>
         <apex:column value="{!item.contact}" headerValue="Contact"/>

     </apex:pageBlockTable> 
 </apex:pageBlock>
</apex:form>
</apex:page>

When I add this page to the community,I am getting the error "Error: Error occurred while loading a Visualforce page." What am I doing wrong here?
I have this user case where a community user needs to see the appointments of all the contacts in his parent account.Appointment has a lookup relationship to contact.  Right now, in the first soql query I am getting the contactid of the user.
myContact=[select id,email, from contact where id =:loggdinUserRecord.contactid];
 The I am running a query to get the account id of that contact:
con=[select account.name,account.id from contact where id=:myContact.id];
and in the third and fourth query, I am getting the contact names for each of those accounts and the appointment for each of those contacts.

Is this how it's supposed to be or can I optimize the soql queries to make it more efficient?
Thanks
 
I have created a Salesforce Community using Napili template. From the builder option, I have created two tabs for both Contact and Opportunity but when I login as a user, I can view all the contacts and opportunities in the org. Can I restrict this, so that the user can only see some fields from his contact and attachments from his opportunity? Can I do this using point and click or do I need visulaforce for this?

Thanks
I am trying to move records from one custom Object(Course_temp__c) to another custom Object(Course__c) using Apex batch. This is the code I have:
global class MyBatchJob2 implements Database.Batchable<Course_temp__c> {

    global MyBatchJob2(){}

    global List<Course_temp__c> start(Database.BatchableContext BC) {
    	return [Select Id, Name, Contact__c, Course_Fees__c,Date__c From Course_temp__c];
    }

    global void execute(Database.BatchableContext BC, List<Course_temp__c> scope) {
       List<Course__c> lhList = new List<Course__c>();
       for(Course_temp__c obj : scope){
           System.debug('Course_temp records are: ' +obj);
           lhList.add(
               new Course__c(
                  Name = obj.Name,
                   Contact__c = obj.Contact__c,
                   Course_Fees__c = obj.Course_Fees__c,
                   Date__c = obj.Date__c
               )
           );
           System.debug('The list is: '+lhlist);
       }
       insert lhList;
       delete scope;
    }

    global void finish(Database.BatchableContext BC) {
        System.debug('Finished Succesfully');
    }
}
I am invoking the batch class using           Id batchJobId = Database.executeBatch(new MyBatchJob2(), 200);

The code is running without any compilation errors and I also get the 'Finished Succesfully' message in the debug log. However, the records are not moving from Course_temp__c to Course__c. Can someone please tell me what I missing. Any help is hugely appreciated.


 
I have this requirement to upload the records from a csv file and populate a custom object Course with fields Id, Name, Contact(Lookup detail to Contact Object), Fees and Date using Apex and Visualforce. This is the apex code I have:
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<Course__c> courlist{get;set;}
public importDataFromCSVController(){
    csvFileLines = new String[]{};
        courlist = New List<Course__c>(); 
}

public void importCSVFile(){
    try{
        csvAsString = csvFileBody.toString();
        csvFileLines = csvAsString.split('\n'); 

        for(Integer i=1;i<csvFileLines.size();i++){
            Course__c couObj = new Course__c();
            string[] csvRecordData = csvFileLines[i].split(',');
            couObj.name = csvRecordData[0] ;  
            couObj.id = csvRecordData[1];

            couObj.Contact__c = csvRecordData[2];
            String temp_fees=csvRecordData[3];
            couObj.Course_fees__c = Decimal.valueOf(temp_fees);
            String temp_date=csvRecordData[4];
            couObj.Course_Date__c = Date.parse(temp_date); 

            courlist.add(couObj);   
        }
        insert courlist;
    }
    catch (Exception e)

    {
        System.debug(e.getCause());
        ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importing data. Please make sure input csv file is correct');
        ApexPages.addMessage(errorMessage);
    }  
}

and the Visualforce code :
<apex:page controller="importDataFromCSVController">
<apex:form >
    <apex:pagemessages />
    <apex:pageBlock >
        <apex:pageBlockSection columns="5"> 
              <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
              <apex:commandButton value="Import Account" action="{!importCSVFile}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock >
       <apex:pageblocktable value="{!courList}" var="cours">
          <apex:column value="{!cours.Id}" />
          <apex:column value="{!cours.Name}" />
          <apex:column value="{!cours.Contact__c}" />
          <apex:column value="{!cours.Course_fees__c}" />
          <apex:column value="{!cours.Course_Date__c}" />
    </apex:pageblocktable>
 </apex:pageBlock>

and the data in the csv file is:
User-added image

When I try to upload this data, I will get the custom error from the Catch block. However if I remove the Id and date field reference from the data as well as from the code, I can successfully upload the data. I am fairly new to coding, so if  someone can point it out to me what I am doing wrong, I would very much appreciate that.

Thanks
I'll start by saying, I'm not a developer.  I'm doing some work for a customer that had a previous company do some work for them, and I'm trying to figure out what they did (and why).

In their partial sandbox, they created an Apex Class (called LeadConversionController).  To me (again, a non-developer) it looks like it just controls where the fields are mapped when a lead is converted.  I tried to delete it, but it can't be deleted because of an "Aura Component Bundle".  When I go to the Aura Component Bundle, it takes me to the Developer Console and that's where it loses me.  I have no idea what I'm looking at.

I know you can't deactivate an Apex Class, but what can I do if I can't delete it?  I also don't see how to get rid of the Bundle. 

Do I just refresh the sandbox and lose whatever it is that they wrote in that Class?  

Why would an Apex Class be written to handle the field conversion?  There is nothing special about the set up (Lead to Account, Contact and Opportunity).

I can show the code if anyone (1) made it this far into my post and (2) can tell me if I'm missing something in the code.

Thank you!
Hi,
I am trying to insert products from lwc component to opportunity object from community. I have a component where there is an option for searching the product based on input and then there is "SAVE" button onclick() it saves the selected product to opportunity. So while searching the product the code is like : 
Select Id,Name,ProductID__c,OldMaterialNumber__c From Product2 where Name like : searchTxt With SECURITY_ENFORCED LIMIT 1000

and for saving the product code is like:
public static List<OpportunityLineItem> opportunityProductCreation(Id oppId, List<OpportunityLineItemWrapper> oliData){
        List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
        id oppRecordId = oppId;
        try {
            if(oliData.size()>0){  
                system.debug('Whole wrapper data print'+oliData);
                system.debug('incoming Opp ID'+oppId);
                for(OpportunityLineItemWrapper oli: oliData){
                    system.debug('Single data at once'+oli);
                    OpportunityLineItem oppLineItem = new OpportunityLineItem();
                    oppLineItem.product2Id          =   oli.selectedProductId;
                    oppLineItem.Opportunityid       =   oppRecordId;
                    oppLineItem.Quantity            =   decimal.valueOf(oli.orderQuantity);
                    oppLineItem.TargetPrice1__c =   decimal.valueOf(oli.targetCost);
                    oppLineItem.ResalePrice__c      =   decimal.valueOf(oli.resalePrice);
                    oppLineItem.CompetitorName__c = oli.competitor;
                    oppLineItem.PriceUnit__c    =   decimal.valueOf(oli.perUnit);
                    oppLineItem.Price1__c     =   decimal.valueOf(oli.Price);
                    oliList.add(oppLineItem);
                }
                system.debug('check all OPPLINEITEM data before insertion');
                insert oliList;
            }
            return oliList;
        } catch (Exception e) {
            system.debug('Error Msg-- ' + e.getMessage() + 'Error Line No-- ' + e.getLineNumber());
            SC_ExceptionLogHandler.createExceptionLog(e,'pdrPartsComponentCls');
            throw new AuraHandledException(e.getMessage());
        }

    }

So here while inserting Data i am recieving this error: 
Insert failed. 
    First exception on row 0; first error: REQUIRED_FIELD_MISSING, 
    Error: You can't select products until you've chosen a price book for this opportunity on the products related list.: []

So can anyone help me what i have to do inorder to save the opportunity from community side.
Thanks.
I have a user case where the community user needs to see all the appointments of all the contacts from their parent account.Here is the Code I have:
 
public class AppointmentListController {

public String AppFilterId {get; set;}
private Integer pageSize = 10;
private String baseQuery ='SELECT Name, contact.name, Status__c FROM appointment__c WHERE contact IN (SELECT Id FROM Contact WHERE AccountId = :myContact.AccountId)';

public AppointmentListController(){
    Contact myContact=[select id,accountid from contact where id in(select contactId from user where id=:userinfo.getuserid())];
}

public ApexPages.StandardSetController AppSetController {
    get{
        if(AppSetController == null){
            AppSetController = new ApexPages.StandardSetController(Database.getQueryLocator(baseQuery));
            AppSetController.setPageSize(pageSize);
            if(AppFilterId != null)
            {
                AppSetController.setFilterId(AppFilterId);
            }
        }
        return AppSetController;
    }set;
}

public AppointmentListController(ApexPages.StandardSetController c) {   }

public void firstPage()
{
    AppSetController.first();
}

public void lastPage()
{
    AppSetController.last();
}

public void next()
{
    if(AppSetController.getHasNext())
    {
        AppSetController.next();
    }
}

public void prev()
{
    if(AppSetController.getHasPrevious())
    {
        AppSetController.previous();
    }
}

public List<appointment__c> getAppoinments()
{
    return (List<appointment__c>)AppSetController.getRecords();
}

public SelectOption[] getAppoinmentExistingViews(){
    return AppSetController.getListViewOptions();
}

public PageReference resetFilter()
{
    AppSetController = null;
    AppSetController.setPageNumber(1);
    return null;
}}

and this is my visualforce page:
 
<apex:page controller="AppointmentListController" sidebar="false" showHeader="false">

<apex:form id="pageForm">

   <apex:actionStatus id="ajaxStatus" startText="Loading..."  stopText=""/>
    <br/><br/>

 <apex:pageBlock title="Appoinments">
    <apex:pageBlockButtons >
            <apex:commandButton action="{!firstPage}" value="|<<" reRender="AppTable"  status="ajaxStatus" />
            <apex:commandButton action="{!prev}" value="Prev" reRender="AppTable"  status="ajaxStatus" />
            <apex:commandButton action="{!next}" value="Next" reRender="AppTable"  status="ajaxStatus" />
            <apex:commandButton action="{!lastPage}" value=">>|" reRender="AppTable"  status="ajaxStatus" />
        </apex:pageBlockButtons>

     <apex:pageBlockTable value="{!Appoinments}" var="item" id="AppTable">
         <apex:column value="{!item.name}" headerValue="Appoinment Name"/>
         <apex:column value="{!item.Status__c}" headerValue="Status"/>
         <apex:column value="{!item.contact}" headerValue="Contact"/>

     </apex:pageBlockTable> 
 </apex:pageBlock>
</apex:form>
</apex:page>

When I add this page to the community,I am getting the error "Error: Error occurred while loading a Visualforce page." What am I doing wrong here?
I have this requirement to upload the records from a csv file and populate a custom object Course with fields Id, Name, Contact(Lookup detail to Contact Object), Fees and Date using Apex and Visualforce. This is the apex code I have:
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{get;set;}
public String[] csvFileLines{get;set;}
public List<Course__c> courlist{get;set;}
public importDataFromCSVController(){
    csvFileLines = new String[]{};
        courlist = New List<Course__c>(); 
}

public void importCSVFile(){
    try{
        csvAsString = csvFileBody.toString();
        csvFileLines = csvAsString.split('\n'); 

        for(Integer i=1;i<csvFileLines.size();i++){
            Course__c couObj = new Course__c();
            string[] csvRecordData = csvFileLines[i].split(',');
            couObj.name = csvRecordData[0] ;  
            couObj.id = csvRecordData[1];

            couObj.Contact__c = csvRecordData[2];
            String temp_fees=csvRecordData[3];
            couObj.Course_fees__c = Decimal.valueOf(temp_fees);
            String temp_date=csvRecordData[4];
            couObj.Course_Date__c = Date.parse(temp_date); 

            courlist.add(couObj);   
        }
        insert courlist;
    }
    catch (Exception e)

    {
        System.debug(e.getCause());
        ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importing data. Please make sure input csv file is correct');
        ApexPages.addMessage(errorMessage);
    }  
}

and the Visualforce code :
<apex:page controller="importDataFromCSVController">
<apex:form >
    <apex:pagemessages />
    <apex:pageBlock >
        <apex:pageBlockSection columns="5"> 
              <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
              <apex:commandButton value="Import Account" action="{!importCSVFile}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock >
       <apex:pageblocktable value="{!courList}" var="cours">
          <apex:column value="{!cours.Id}" />
          <apex:column value="{!cours.Name}" />
          <apex:column value="{!cours.Contact__c}" />
          <apex:column value="{!cours.Course_fees__c}" />
          <apex:column value="{!cours.Course_Date__c}" />
    </apex:pageblocktable>
 </apex:pageBlock>

and the data in the csv file is:
User-added image

When I try to upload this data, I will get the custom error from the Catch block. However if I remove the Id and date field reference from the data as well as from the code, I can successfully upload the data. I am fairly new to coding, so if  someone can point it out to me what I am doing wrong, I would very much appreciate that.

Thanks