• SR02
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
I am having a requirement to create account record when logged in as a user whose profile is not having create access to accounts.  And the controller which is being used by lightning component has been declared as without sharing. However I am still getting insufficient access error at the line where i am inserting new accounts. 
Now I am totally confused with the concept of without sharing which runs in system mode still looks for the profile level settings?? 
Some one please help me to resolve this issue.
  • August 26, 2019
  • Like
  • 0

hi,

 

i am new to SOQL. Please help me with this problem.

 

I have created two object Depts(Parent -Master) and Emp(child) and the common fld is deptid__c

 

I am trying to use below query in my code to retrieve values.

 

select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c in(select did__c from dept__c where did__c='D-0002'

 

but it is giving me the error "System.QueryException: semi join sub selects can only query id fields, cannot use: 'did__c'"

 

I tried using below

 

select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c = 'D-0002'

 

which gave me error System.QueryException: invalid ID field: D-0002

 

how to resolve this .

please suggest me

select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c in(select did__c from dept__c where did__c='D-0002')
  • June 02, 2012
  • Like
  • 0

hi,

 

I am learning Apex and VF. I need to display the records based on the selected department.  When I trying to get the selectedpick list value in my controller it is not getting returned.

 

Please suggest me some solution.

 

public class deptpicklistctrl{

    public void search() {
        system.debug('****in getemplist****');
        empobj = [select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c=:selectedval];
        //system.debug(empobj.get(0).name);
        //Pagereference p= apexpages.currentpage();
        //return p;
        
    }

    public List<dept__c> deptobj{get;set;}
    public List<emp__c> empobj{get;set;}
    public String selectedval{get{return selectedval;}set{this.selectedval=selectedval;}}
    
    public deptpicklistctrl()
    {
    //search();
    }
    
    public List<SelectOption> getDeptnos(){
        deptobj = [select name from dept__c];
        List<SelectOption> lis = new List<SelectOption>();
        
        for(dept__c d:deptobj){
            lis.add(new SelectOption(d.name,d.name));
        }
        return lis;
        
    }

}

 

// VF page

 

<apex:page controller="deptpicklistctrl" showHeader="false">
  <apex:form >
  <apex:pageBlock mode="edit">
  <apex:pageBlockSection title="Select from Pick List">
  <apex:outputText value="Department : "/>
  <apex:selectList value="{!selectedval}" size="1">
  <apex:selectOptions value="{!deptnos}"></apex:selectOptions>
  </apex:selectList>
  <apex:commandButton value="Search" action="{!search}" reRender="block" />
  </apex:pageBlockSection>
  </apex:pageblock>
 <apex:pageBlock mode="edit" id="block">
  <apex:pageblockSection title="Employee List in the department">
  <apex:pageBlockTable value="{!empobj}" var="bj">
  <apex:column value="{!bj.name}"/>
    <apex:column value="{!bj.EmpName__c}"/>
      <apex:column value="{!bj.EmpID__c}"/>
        <apex:column value="{!bj.DeptID__c}"/>
  </apex:pageBlockTable>
  </apex:pageblockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

  • June 02, 2012
  • Like
  • 0

Hi,

 

I am very new to salesforce trying to create some space for myself.

In my logincontroller once after the user login is succeeded I am setting the name of the user like below and redirecting to mainmenu page.

 

PageReference pageRef = Page.mainmenu;
system.debug('in login page***'+userlst.get(0).name);
pageRef.getParameters().put('usrnm',userlst.get(0).name);
return Page.mainmenu;

 

 

And I am trying to retrieve the same in "mainmenu" page controller using below

 

public mainmenuController(){

this.strname=Apexpages.currentPage().getParameters().get('usrnm');
system.debug('****in menu***'+strname);
}

 

however in mainmenucontroller the value of "strname" is printing as null

 

any ideas/suggestions are most welcome.

  • May 17, 2012
  • Like
  • 0
Hi,

I am facing below error while trying to verify Step 8-
Error: Please ensure that product2Extension and its methods are still working as specified in the earlier challenge.

Code below:
public class Product2Extension {

    public List<ProductWrapper> productsToInsert {get;set;}

    public Product2Extension(ApexPages.StandardController controller){
        productsToInsert = new List<ProductWrapper>();
        addRows();
    }
    
    public List<SelectOption> GetFamilyOptions() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption(Constants.SELECT_ONE, Constants.SELECT_ONE));
        for(PickListEntry eachPicklistValue : Constants.PRODUCT_FAMILY) {
            options.add(new SelectOption(eachPicklistValue.getValue(), eachPicklistValue.getLabel()));
        }
            return options;
    }
    
    public void AddRows(){
        for (Integer i=0; i<Constants.DEFAULT_ROWS; i++ ){
            productsToInsert.add(new ProductWrapper());
        }
    }

    public List<ChartHelper.ChartData> GetInventory(){
        return ChartHelper.GetInventory();
    }

    public PageReference Save(){
        SavePoint sp = Database.setSavepoint();
        Integer insertedCount = 0;
        try {
            List<Product2> newProducts = new List<Product2>();
            List<PriceBookEntry> pbeList = new List<PriceBookEntry>();
            List<ProductWrapper> filteredProductWrappers = new List<ProductWrapper>();
            for(ProductWrapper eachPW : productsToInsert) {
                if(!String.isBlank(eachPW.productRecord.Name) && !String.isBlank(eachPW.productRecord.Family) && 
                   eachPW.productRecord.Family!=Constants.SELECT_ONE && eachPW.productRecord.isActive &&
                   eachPW.pricebookEntryRecord.UnitPrice!=null && eachPW.productRecord.Initial_Inventory__c!=null && 
                   eachPW.productRecord.Initial_Inventory__c!=0 && eachPW.pricebookEntryRecord.UnitPrice!=0) {
                       filteredProductWrappers.add(eachPW);
                   }                
            }
            for(ProductWrapper eachPW : filteredProductWrappers) {
                newProducts.add(eachPW.productRecord);
            }
            Database.SaveResult[] productSaveResults = Database.insert(newProducts, false);
            for(Integer i=0; i<productSaveResults.size(); i++) {
                if(productSaveResults[i].isSuccess()) {
                    PriceBookEntry pbe = filteredProductWrappers[i].pricebookEntryRecord;
                    pbe.Product2Id = productSaveResults[i].getId();
                    pbe.IsActive = true;
                    pbe.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
                    pbeList.add(pbe);
                    insertedCount++;
                }
            }
            Database.SaveResult[] pbeSaveResults = Database.insert(pbeList, false);
            
            //If successful clear the list and display an informational message
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,insertedCount + ' Inserted'));
            productsToInsert.clear();   //Do not remove
            addRows();  //Do not remove
        } 
        catch (Exception e){
            System.debug('Exception occured:'+e.getMessage());
            Database.rollback(sp);
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, Constants.ERROR_MESSAGE));            
        }
        return null;
    }
    
    public class ProductWrapper {
        public Product2 productRecord {get;set;}
        public PriceBookEntry pricebookEntryRecord {get;set;}
        
        public ProductWrapper() {
            productRecord = new Product2();
            pricebookEntryRecord = new PricebookEntry();
        }
    }
}

hi,

 

i am new to SOQL. Please help me with this problem.

 

I have created two object Depts(Parent -Master) and Emp(child) and the common fld is deptid__c

 

I am trying to use below query in my code to retrieve values.

 

select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c in(select did__c from dept__c where did__c='D-0002'

 

but it is giving me the error "System.QueryException: semi join sub selects can only query id fields, cannot use: 'did__c'"

 

I tried using below

 

select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c = 'D-0002'

 

which gave me error System.QueryException: invalid ID field: D-0002

 

how to resolve this .

please suggest me

select name,empname__c,empid__c,deptid__c from emp__c  where deptid__c in(select did__c from dept__c where did__c='D-0002')
  • June 02, 2012
  • Like
  • 0

Hi,

 

I am very new to salesforce trying to create some space for myself.

In my logincontroller once after the user login is succeeded I am setting the name of the user like below and redirecting to mainmenu page.

 

PageReference pageRef = Page.mainmenu;
system.debug('in login page***'+userlst.get(0).name);
pageRef.getParameters().put('usrnm',userlst.get(0).name);
return Page.mainmenu;

 

 

And I am trying to retrieve the same in "mainmenu" page controller using below

 

public mainmenuController(){

this.strname=Apexpages.currentPage().getParameters().get('usrnm');
system.debug('****in menu***'+strname);
}

 

however in mainmenucontroller the value of "strname" is printing as null

 

any ideas/suggestions are most welcome.

  • May 17, 2012
  • Like
  • 0