• Jaggy
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 23
    Replies

I wanted to create a trigger that basically copies the first 50 characters of the Comments field in Task to a custom field. It looks kinda like this

 

for (Task tasksToUpdate: trigger.new){
Integer max=tasksToUpdate.Description.length();
if (max != 0) {
Integer endCharacter = 0;
if (max < 50)
endCharacter = max;
else
endCharacter = 50;
tasksToUpdate.Comments_Short__c = tasksToUpdate.Description.substring(0,endCharacter) ;
}
}

All well and good, but when I try to execute this with a blank Comments field, the error "execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object" shows up. I think I'm supposed to have a catch-exception when it is blank/null, but I can't understand why this doesn't work. Any ideas?

I am trying to get complete coverage for my test class and cannot get there as I cannot get passed 56%.  Can anyone point me in the right direction?

 

Class

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem {get;set;}
    public ID<Order__c> oid {get;set;}
    public string orderid;
    public integer iqty;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public PageReference saveitems()
    {
        //Save item relationships
        List<Order_Item_Junction__c> insitems = new List<Order_Item_Junction__c>();
        try{
            for(integer i=0;i<lstoitem.size();i++)
                {
                if(lstoitem[i].Quantity__c > 0)
                    {
                    Order_Item_Junction__c qtyitem = new Order_Item_Junction__c();
                    qtyitem.Order__c = oid;
                    qtyitem.Product_Bundle__c = lstbundle[i].Id;
                    qtyitem.Quantity__c = lstoitem[i].Quantity__c;
                    insitems.add(qtyitem);
                    }
                }
            if(insitems.size()>0)
                insert insitems;
        }catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
        return null; 
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        
            if(orecordtype == 'New Order')
            {            
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        lstoitem = new List<Order_Item_Junction__c>();
        oid = orderid;
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = oid;
            oitem.Quantity__c = 0;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 

 

Page

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script language="JavaScript" type="text/javascript">
function CloseAndRefresh()
{
    window.opener.location.href="/{!$CurrentPage.parameters.oid}";
    window.top.close();
      
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headerValue="Order" value="{!l.Order__c}" width="40%"/>
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="40%"/>
                        <apex:column headerValue="Quantity" id="iqty" width="20%">
                            <apex:inputField value="{!l.Quantity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Test Class

@isTest
private class oitemControllerTest
{
    static testmethod void testorderNew1()
    {
        delete [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];

        RecordType recnew = [select ID, Name from RecordType where Name = 'New Order' and SObjectType = 'Order__c'];
        RecordType recreturn = [select ID, Name from RecordType where Name = 'Return Order' and SObjectType = 'Order__c'];
        
        Order__c order1 = new Order__c(recordtypeid=recnew.Id);
        insert order1;
        
        Order__c order2 = new Order__c(recordtypeid=recreturn.Id);
        insert order2;
        
        RecordType recopen = [select ID, Name from RecordType where Name = 'Open' and SObjectType = 'Product_Bundle__c'];
        RecordType recreturnbun = [select ID, Name from RecordType where Name = 'Open' and SObjectType = 'Product_Bundle__c'];
        
        Product_Bundle__c bundle1 = new Product_Bundle__c(recordtypeid = recopen.id, Name = 'TestBundle1', Description__c = 'Testing1', Completed__c = TRUE, Order_Availability__c = 'New Order');
        Product_Bundle__c bundle2 = new Product_Bundle__c(recordtypeid = recreturnbun.id, Name = 'TestBundle2', Description__c = 'Testing2', Completed__c = TRUE, Order_Availability__c = 'Return Order');
        Product_Bundle__c bundle3 = new Product_Bundle__c(recordtypeid = recopen.id, Name = 'TestBundle3', Description__c = 'Testing3', Completed__c = FALSE, Order_Availability__c = 'New Order');
        Product_Bundle__c bundle4 = new Product_Bundle__c(recordtypeid = recreturnbun.id, Name = 'TestBundle1', Description__c = 'Testing4', Completed__c = FALSE, Order_Availability__c = 'Return Order');
        Product_Bundle__c [] bundle_array = new Product_Bundle__c []{bundle1,bundle2,bundle3,bundle4};
        insert bundle_array;
        
        Order_Item_Junction__c oi1 = new Order_Item_Junction__c(Order__c = order1.Id,Product_Bundle__c = bundle1.id, Quantity__c = 1);
        Order_Item_Junction__c oi2 = new Order_Item_Junction__c(Order__c = order1.Id,Product_Bundle__c = bundle2.id, Quantity__c = 2);
        Order_Item_Junction__c oi3 = new Order_Item_Junction__c(Order__c = order2.Id,Product_Bundle__c = bundle3.id, Quantity__c = 1);
        Order_Item_Junction__c oi4 = new Order_Item_Junction__c(Order__c = order2.Id,Product_Bundle__c = bundle4.id, Quantity__c = 2);        
        Order_Item_Junction__c [] oi_array = new Order_Item_Junction__c []{oi1,oi2};
        insert oi_array;
        
        PageReference pref1 = Page.orderpage;
        pref1.getParameters().put('oid',order1.Id);
        pref1.getParameters().put('orecordtype',recnew.Name);
        Test.setCurrentPage(pref1);
        
        ApexPages.StandardController stdcon1 = new ApexPages.StandardController(oi_array[0]);
        oitemController oicon1 = new oitemController(stdcon1);
        oicon1.setproceed();
        oicon1.saveitems();

        PageReference pref2 = Page.orderpage;
        pref2.getParameters().put('oid',order2.Id);
        pref2.getParameters().put('orecordtype',recreturn.Name);
        pref2.getParameters().put('orecordtype',recreturn.Name);
        Test.setCurrentPage(pref2);
        
        ApexPages.StandardController stdcon2 = new ApexPages.StandardController(oi_array[5]);
        oitemController oicon2 = new oitemController(stdcon2);
        oicon1.setproceed();
        oicon1.saveitems();
            
    }
}

 

 

  • March 01, 2012
  • Like
  • 0

Hi,

 

I started security review from my appexchange publisher profile. But salesforce sent me following email

 

Thank you for requesting to initiate the Security Review process. Before we can begin, your application must first be enrolled in the AppExchange Partner Program.  Please reach out to the individuals cc’d on this email for assistance. After you have successfully joined the program, please return to your AppExchange publisher and reinitiate Security Review on this package. 

We look forward to building a strong partnership with much shared success. 

 

How can enroll in AppExchange Partner Program. I asked them too but they haven't replied yet.

 

 

Thanks

Jagdeep

  • September 05, 2012
  • Like
  • 0

Hi,

 

I am using following code to insert an account but it doesnt work. Can anyone tell me what I am missing here.

<apex:page >
    <link rel="stylesheet" type="text/css" href="{!URLFOR($Resource.extjs,'extjs-4.1.0/resources/css/ext-all.css')}"/>
    <script type="text/javascript" src="{!URLFOR($Resource.extjs, 'extjs-4.1.0/ext-all.js')}"></script>

    <script type="text/javascript">
        Ext.define('Jaggy.Account', {
            extend: 'Ext.data.Model',
            fields: [
                'id',
                'name',
                'type',
                'industry',
                'active__c',
                'website',
                'owner'
            ],
            proxy: {
                type: 'rest',
                url: 'https://ap12.salesforce.com/services/proxy',
                headers: {
                    'SalesforceProxy-Endpoint': 'https://ap12.salesforce.com/services/data/v25.0/sobjects/Account',
                    'Authorization': 'OAuth {!GETSESSIONID()}',
                    'Accept': 'application/json'
                },
                format: 'json',
                reader: {
                    type: 'json',
                    root: 'records'
                }
            }
        });
        
        var acc = Ext.create('Jaggy.Account', {
            name: 'Mandeep'
        });
        
        acc.save(); 
      
    
    </script>
</apex:page>

 

  • July 19, 2012
  • Like
  • 0

Hi Guys,

 

I've created a custom field on salesforce CRM content object. Its a formula field. When I try to add this field to my managed package then it does not show up when we select custom field from drop-down. 

 

I also checked package contents and its also not there. So, how can I add this field to my package. Any idea or suggestions?

 

 

Thanks

Jagdeep

  • July 11, 2012
  • Like
  • 0

Hi Guys,

 

I need some help regarding debug logs in production.

 

My production users are getting an error while running a vf page. I want to debug this case in production since I am unable to reproduce the same error into dev org. There in dev org, everything works fine. So my question is that "are the debug logs created for every production user automatically by the salesforce?

 

I found it that we can only create 20 debug logs for a user after that we need to reset. How does it work?

When I reset it for the first time after that count 20 does not get decremented. It remains fixed.

 

 

Thanks

  • June 27, 2012
  • Like
  • 0

Hi Guys,

 

I'm using following code for checking life cycle of a vf page.

public with sharing class lifecycle {
    public String s {
        get {
            System.debug('----------------In Get-------------');
            return 'Jagdeep';
        }
        set {
            System.debug('----------------In Set-------------');
        }
    }
    
    public void myact() {
        System.debug('----------------In Act-------------');
    }
}

 

<apex:page controller="lifecycle">
{!s}
<apex:form>
<apex:inputtext value="{!s}"/>
<apex:commandButton action="{!myact}" value="action"/>
</apex:form>
</apex:page>

 The log which generated after hitting action button is as follows

24.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:52:31.021 (21567000)|EXECUTION_STARTED
14:52:31.021 (21605000)|CODE_UNIT_STARTED|[EXTERNAL]|066U0000000X8Ey|VF: /apex/jaggy__lifecycle
14:52:31.021 (21797000)|VF_DESERIALIZE_VIEWSTATE_BEGIN|066U0000000X8Ey
14:52:31.023 (23967000)|VF_DESERIALIZE_VIEWSTATE_END
14:52:31.024 (24575000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle get(s)
14:52:31.024 (24587000)|SYSTEM_MODE_ENTER|true
14:52:31.024 (24604000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|s
14:52:31.025 (25308000)|METHOD_ENTRY|[1]|01pU00000016Hc7|lifecycle.lifecycle()
14:52:31.025 (25381000)|SYSTEM_MODE_ENTER|false
14:52:31.025 (25389000)|SYSTEM_MODE_EXIT|false
14:52:31.025 (25396000)|METHOD_EXIT|[1]|lifecycle
14:52:31.025 (25404000)|SYSTEM_MODE_ENTER|false
14:52:31.025 (25447000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
14:52:31.025 (25471000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26087000)|USER_DEBUG|[4]|DEBUG|----------------In Get-------------
14:52:31.026 (26102000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
14:52:31.026 (26114000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26125000)|CODE_UNIT_FINISHED|s
14:52:31.026 (26133000)|CODE_UNIT_FINISHED|lifecycle get(s)
14:52:31.026 (26218000)|CODE_UNIT_STARTED|[EXTERNAL]|lifecycle set(s,Jagdeep)
14:52:31.026 (26228000)|SYSTEM_MODE_ENTER|true
14:52:31.026 (26244000)|CODE_UNIT_STARTED|[EXTERNAL]|lifecycle set(s,Jagdeep)
14:52:31.026 (26322000)|SYSTEM_MODE_ENTER|false
14:52:31.026 (26341000)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
14:52:31.026 (26349000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26372000)|USER_DEBUG|[8]|DEBUG|----------------In Set-------------
14:52:31.026 (26379000)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
14:52:31.026 (26383000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26389000)|CODE_UNIT_FINISHED|lifecycle set(s,Jagdeep)
14:52:31.026 (26394000)|CODE_UNIT_FINISHED|lifecycle set(s,Jagdeep)
14:52:31.026 (26506000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle invoke(myact)
14:52:31.026 (26542000)|SYSTEM_MODE_ENTER|false
14:52:31.026 (26556000)|SYSTEM_METHOD_ENTRY|[13]|System.debug(ANY)
14:52:31.026 (26560000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26580000)|USER_DEBUG|[13]|DEBUG|----------------In Act-------------
14:52:31.026 (26587000)|SYSTEM_METHOD_EXIT|[13]|System.debug(ANY)
14:52:31.026 (26591000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26619000)|CODE_UNIT_FINISHED|lifecycle invoke(myact)
14:52:31.026 (26638000)|VF_APEX_CALL|j_id4|{!myact}|PageReference: none
14:52:31.039 (39212000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle get(s)
14:52:31.039 (39226000)|SYSTEM_MODE_ENTER|true
14:52:31.039 (39236000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|s
14:52:31.039 (39273000)|SYSTEM_MODE_ENTER|false
14:52:31.039 (39291000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
14:52:31.039 (39296000)|ENTERING_MANAGED_PKG|
14:52:31.039 (39306000)|USER_DEBUG|[4]|DEBUG|----------------In Get-------------
14:52:31.039 (39314000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
14:52:31.039 (39319000)|SYSTEM_MODE_EXIT|false
14:52:31.039 (39327000)|CODE_UNIT_FINISHED|s
14:52:31.039 (39332000)|CODE_UNIT_FINISHED|lifecycle get(s)
14:52:31.040 (40451000)|VF_SERIALIZE_VIEWSTATE_BEGIN|066U0000000X8Ey
14:52:31.041 (41722000)|VF_SERIALIZE_VIEWSTATE_END
14:52:31.301 (44149000)|CUMULATIVE_LIMIT_USAGE
14:52:31.301|LIMIT_USAGE_FOR_NS|jaggy|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 6 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

This log is only after action button is invoked. I dont know why it is printing '---------------in get----------------' string. Any suggestion on that.

 

 

  • April 17, 2012
  • Like
  • 0

Hi Guys,

 

I am using a custom controller attached to a VF page as follows:

public without sharing class AccountController {

    private final Account account;
    public AccountController() {
    account = [select id, name, site from Account where id =
    :ApexPages.currentPage().getParameters().get('id')];
    }
    public Account getAccount() {
    return account;
    }
    public PageReference save() {
    update account;
    return null;
    }
    
}

 

<apex:page controller="AccountController"> 
    {!account.name}
</apex:page>

 I've a profile Standard Employee which doesnt have read access to account and OWD for account is public read only. Now when i login as standard employee and opens vf page then no account name is displayed. According to me in system mode profile based permissions and FLS is not enforced. So what i am missing here?

  • April 17, 2012
  • Like
  • 0

hi guys,

 

I am using standard list controller and want to print current page set record count. How can we achieve this without using extensions?  

 

<apex:page standardController="Account" recordSetVar="accounts">
    {!accounts.length()}

</apex:page>

  length and size methods are not working.

  • April 17, 2012
  • Like
  • 0

Hi Guys,

 

I'm using following code for rendering an account record and its contacts. My user from a profile doesnt have read access to contact object. So to avoid error message I've used "$ObjectType.Contact.accessible". But it doesn't seem working for me.

Can you tell what I am missing here?

 

<apex:page standardController="account" tabstyle="Attendance__c">
<apex:form>
<apex:pageBlock title="My Content">

    <apex:pageBlockTable value="{!account.Contacts}" var="item" rendered="{!$ObjectType.contact.accessible}">
    
        <apex:column value="{!item.name}"/> 
    
    </apex:pageBlockTable> 

</apex:pageBlock> 
</apex:form>

<apex:detail rendered="{!$ObjectType.account.accessible}"/>

</apex:page>

 

  • April 16, 2012
  • Like
  • 0

Hi,

 

Presently, when you create a task on a record. It by default assigns task to the current logged in user. It seems logical too. But I want to assign it to owner of the record instead of logged in user by default. Is there any way of doing this?

 

 

  • March 08, 2012
  • Like
  • 0

Hi,

 

I have a VF page which uses standard controller and controller extension. Standard object is Account and I am displaying Contacts in standard way. I've delete button on every contact row which in turn call an action and passes record id of contact as param. But deletion is not working.

VF

                    <apex:pageblockTable value="{!Account.Contacts}" var="r"  styleClass="inline-editable" >
                        <apex:column headerValue="Action" width="50">
                            <apex:commandLink action="{!onDeleteContact}" rerender="iprs-id" 
                                            status="preloader2" onclick="var con = confirm('Are you sure?');if(con==false)return false;">
                                <apex:image url="{!URLFOR($Resource.icons,'delete_icon.gif')}" title="delete" />
                                <apex:param name="OwnerId" value="{!r.id}" />
                            </apex:commandLink> 
                        </apex:column>

                        <apex:column headerValue="Contact Name">
                        <apex:outputField value="{!r.Name}" />
                            
                        </apex:column>

                       
                    </apex:pageblockTable>

 Controller code

	public void onDeleteContact() {

		Id cId = ApexPages.currentPage().getParameters().get('CId');
		
		Integer i = -1;
		Boolean flag = false;
		for (Contact c : acc.contacts) {
			i++;
			if (c.Id == cId) {
				flag = true;
				break;
			}
		}
		
		System.debug('i-' + i);
		
		if(flag) {
			System.debug('Owners1-' + acc.contacts);
			delete acc.contacts.remove(i);
			System.debug('Owners2-' + acc.contacts);
			update acc.contacts;
		}
		
	}

 

here acc is reference to account (acc = (Account)stdcon.getRecord();)

I am using rerender on VF page. I just want to table to referesed only. But my deletes the contact record but account.contacts does not get updated. I don't know how to do this. But when I remove rerendering then it works fine. Can anyone tell me what I am missing here.

  • March 08, 2012
  • Like
  • 0

Hi,

 

I've written a test method and I've to test the functionality by different users. So I've used System.runAs for that. But it's not working as I expected. Below is my code.

 

        Profile projectManagerProfile = [SELECT Id FROM Profile WHERE Name = 'Project Manager'];
        Profile teamMemberProfile = [SELECT Id FROM Profile WHERE Name = 'Team Member'];        

        User projectManager = new User(alias = 'promgr', 
                                       email = 'pm@aaaa.co.uk', 
                                       emailencodingkey = 'UTF-8', 
                                       lastname = 'Testing', 
                                       languagelocalekey = 'en_US', 
                                       localesidkey = 'en_US', 
                                       profileid = projectManagerProfile.Id, 
                                       timezonesidkey = 'Europe/London', 
                                       username = 'xxxpm.aaa@aa.co.uk');  
        
        User teamMemberRead = new User(alias = 'tmr', 
                                       email = 'team.member.read@precursive.co.uk', 
                                       emailencodingkey = 'UTF-8', 
                                       lastname = 'Testing', 
                                       languagelocalekey = 'en_US', 
                                       localesidkey = 'en_US', 
                                       profileid = teamMemberProfile.Id, 
                                       timezonesidkey = 'Europe/London', 
                                       username = 'xxxteam.member.read@precursive.co.uk');  
        
        User teamMemberWrite = new User(alias = 'tmw', 
                                        email = 'team.member.write@aaa.co.uk', 
                                        emailencodingkey = 'UTF-8', 
                                        lastname = 'Testing', 
                                        languagelocalekey = 'en_US', 
                                        localesidkey = 'en_US', 
                                        profileid = teamMemberProfile.Id, 
                                        timezonesidkey = 'Europe/London', 
                                        username = 'xxxteam.member.write@aaaa.co.uk');  
                                        
        insert new User[]{projectManager, teamMemberRead, teamMemberWrite};     
        
        Project__c project = null;
        Phase__c phase = null;	// default phase of a project
        Team_Member__c teamMember1 = null;
        Team_Member__c teamMember2 = null;
        

        // Login as PM and create a project
        System.runAs(projectManager) {
            project = new Project__c(Name = 'XXX My Dummy Project XXX',                                      
                                                Start_Date__c = System.today(),
                                                End_Date__c = System.today().addYears(1),
                                                Description__c = 'XXX My Dummy Desc XXX');          
            insert project;
            
            // A default phase is always created upon creation of a project.
            // So we don't need to create one seperatley.                                 
            phase = [SELECT Id FROM Phase__c WHERE Name = 'XXX My Dummy Project XXX - Phase 1' and Project__c = :project.Id];   

            teamMember1 = new Team_Member__c(Name = 'XXX My Team Member Read XXX',
                                   			 Project__c = project.Id,
                                   			 Phase__c = phase.Id,
                                   			 User__c = teamMemberRead.Id,
                                   			 Access__c = 'Read');
           
            teamMember2 = new Team_Member__c(Name = 'XXX My Team Member Write XXX',
                                   			 Project__c = project.Id,
                                   			 Phase__c = phase.Id,
                                   			 User__c = teamMemberWrite.Id,
                                   			 Access__c = 'Write');
            
            insert new Team_Member__c[]{teamMember1, teamMember2};
        }
        
        /* Testing begins */
        // Check for both team members,
        // they should have at least "read" access to the phase record.
        
        System.runAs(teamMemberRead) {
            Phase__c ph;
            try {
                ph = Database.query('SELECT Id FROM Phase__c WHERE Id = \'' + phase.Id + '\' and Name = \'XXX My Dummy Project XXX - Phase 1\'');                
            } catch (Exception e) {System.debug('########-' + e);}
            
            System.assertNotEquals(null, ph);
        }

 My assert gets failed. It shows that 'ph' is null. According to me it shouldn't be null. What am I missing here.

  • March 01, 2012
  • Like
  • 0

Hi,

 

I'm using following trigger for sharing records to hiring manager via apex

 

trigger Hiring_Manager_Job_Share on Position__c (after insert) {

    // We only execute the trigger after a Job record has been inserted 
    // because we need the Id of the Job record to already exist.
    if(trigger.isInsert){
     
    // Job_Share is the "Share" table that was created when the
    // Organization Wide Default sharing setting was set to "Private".
    // Allocate storage for a list of Position__Share records.
    List<Position__Share> jobShares  = new List<Position__Share>();

    // For each of the Job records being inserted, do the following:
    for(Position__c job : trigger.new){

        // Create a new Position__Share record to be inserted in to the Job_Share table.
        Position__Share hiringManagerShare = new Position__Share();
            
        // Populate the Position__Share record with the ID of the record to be shared.
        hiringManagerShare.ParentId = job.Id;
            
        // Then, set the ID of user or group being granted access. In this case,
        // we’re setting the Id of the Hiring Manager that was specified by 
        // the Recruiter in the Hiring_Manager__c lookup field on the Job record.  
        // (See Image 1 to review the Job object's schema.)
        hiringManagerShare.UserOrGroupId = job.Hiring_Manager__c;
            
        // Specify that the Hiring Manager should have edit access for 
        // this particular Job record.
        hiringManagerShare.AccessLevel = 'read';
            
        // Specify that the reason the Hiring Manager can edit the record is 
        // because he’s the Hiring Manager.
        // (Hiring_Manager_Access__c is the Apex Sharing Reason that we defined earlier.)
        hiringManagerShare.RowCause = Schema.Position__Share.RowCause.Hiring_Manager_Access__c;
            
        // Add the new Share record to the list of new Share records.
        jobShares.add(hiringManagerShare);
    }
        
    // Insert all of the newly created Share records and capture save result 
    insert jobShares;
        
    // Error handling code omitted for readability.
    }
}

 

and OWD for Position__c is Publice Read Only.

 

Now, when I create a new position record I get this error

Apex trigger Hiring_Manager_Job_Share caused an unexpected exception, contact your administrator: Hiring_Manager_Job_Share: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: AccessLevel (trivial share level Read, for organization with default level Read): [AccessLevel]: Trigger.Hiring_Manager_Job_Share: line 41, column 1

 

I can understand that this is trivial case and can be passed why my code is not working? What I am missing here?

  • February 24, 2012
  • Like
  • 0

Hi,

 

In apex, How can we determine OWD setting (Org Wide Defaults) for a particular object if we already know object name?

 

 

 

  • February 24, 2012
  • Like
  • 0

Hi guys,

 

I am using phonegap and salesforce mobile SDK. I want to post a file to chatter. But I am unable to make out. Following is my code snippet. Any kind of help will be highly appriciated.

 

    	
        var comment = $("#comment").val();
    				 
	var params = new Object();
	params.desc = "description";
	params.fileName = "filename";
	params.text = comment;
        params.feedItemFileUpload = imageData; // response from phonegap getPicture methods
    				 
        forcetkClient.createFeedItem(params, postSuccess, postError);


    forcetk.Client.prototype.createFeedItem = function(fields, callback, error) {
    	  var str = [];
          for(var p in fields)
	     str.push(p + "=" + encodeURIComponent(fields[p]));
		  
	str = str.join("&");
		  
        this.ajax('/' + this.apiVersion + '/chatter/feeds/news/me/feed-items'
        , callback, error, "POST", str);
    }

 

Thanks

  • February 16, 2012
  • Like
  • 0

Hi,

 

I started security review from my appexchange publisher profile. But salesforce sent me following email

 

Thank you for requesting to initiate the Security Review process. Before we can begin, your application must first be enrolled in the AppExchange Partner Program.  Please reach out to the individuals cc’d on this email for assistance. After you have successfully joined the program, please return to your AppExchange publisher and reinitiate Security Review on this package. 

We look forward to building a strong partnership with much shared success. 

 

How can enroll in AppExchange Partner Program. I asked them too but they haven't replied yet.

 

 

Thanks

Jagdeep

  • September 05, 2012
  • Like
  • 0

Hi Guys,

 

I need some help regarding debug logs in production.

 

My production users are getting an error while running a vf page. I want to debug this case in production since I am unable to reproduce the same error into dev org. There in dev org, everything works fine. So my question is that "are the debug logs created for every production user automatically by the salesforce?

 

I found it that we can only create 20 debug logs for a user after that we need to reset. How does it work?

When I reset it for the first time after that count 20 does not get decremented. It remains fixed.

 

 

Thanks

  • June 27, 2012
  • Like
  • 0

Hello,

 

I have a requirement where I will have to convert a unique 64 character string to a unique 20 character string. 

 

Eg:

Input:abcdef57AgYi8oPidnskd908234ksdjsdjlsdjksd092kj

Output: asdf123asdf123asdf12

 

Everytime i give the same input i should get the same output. We have around 5+ Million records to be updated.

 

Please let me know if you have any ideas around solving the problem.

 

Thanks.

Hi Guys,

 

I'm using following code for checking life cycle of a vf page.

public with sharing class lifecycle {
    public String s {
        get {
            System.debug('----------------In Get-------------');
            return 'Jagdeep';
        }
        set {
            System.debug('----------------In Set-------------');
        }
    }
    
    public void myact() {
        System.debug('----------------In Act-------------');
    }
}

 

<apex:page controller="lifecycle">
{!s}
<apex:form>
<apex:inputtext value="{!s}"/>
<apex:commandButton action="{!myact}" value="action"/>
</apex:form>
</apex:page>

 The log which generated after hitting action button is as follows

24.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
14:52:31.021 (21567000)|EXECUTION_STARTED
14:52:31.021 (21605000)|CODE_UNIT_STARTED|[EXTERNAL]|066U0000000X8Ey|VF: /apex/jaggy__lifecycle
14:52:31.021 (21797000)|VF_DESERIALIZE_VIEWSTATE_BEGIN|066U0000000X8Ey
14:52:31.023 (23967000)|VF_DESERIALIZE_VIEWSTATE_END
14:52:31.024 (24575000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle get(s)
14:52:31.024 (24587000)|SYSTEM_MODE_ENTER|true
14:52:31.024 (24604000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|s
14:52:31.025 (25308000)|METHOD_ENTRY|[1]|01pU00000016Hc7|lifecycle.lifecycle()
14:52:31.025 (25381000)|SYSTEM_MODE_ENTER|false
14:52:31.025 (25389000)|SYSTEM_MODE_EXIT|false
14:52:31.025 (25396000)|METHOD_EXIT|[1]|lifecycle
14:52:31.025 (25404000)|SYSTEM_MODE_ENTER|false
14:52:31.025 (25447000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
14:52:31.025 (25471000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26087000)|USER_DEBUG|[4]|DEBUG|----------------In Get-------------
14:52:31.026 (26102000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
14:52:31.026 (26114000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26125000)|CODE_UNIT_FINISHED|s
14:52:31.026 (26133000)|CODE_UNIT_FINISHED|lifecycle get(s)
14:52:31.026 (26218000)|CODE_UNIT_STARTED|[EXTERNAL]|lifecycle set(s,Jagdeep)
14:52:31.026 (26228000)|SYSTEM_MODE_ENTER|true
14:52:31.026 (26244000)|CODE_UNIT_STARTED|[EXTERNAL]|lifecycle set(s,Jagdeep)
14:52:31.026 (26322000)|SYSTEM_MODE_ENTER|false
14:52:31.026 (26341000)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
14:52:31.026 (26349000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26372000)|USER_DEBUG|[8]|DEBUG|----------------In Set-------------
14:52:31.026 (26379000)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
14:52:31.026 (26383000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26389000)|CODE_UNIT_FINISHED|lifecycle set(s,Jagdeep)
14:52:31.026 (26394000)|CODE_UNIT_FINISHED|lifecycle set(s,Jagdeep)
14:52:31.026 (26506000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle invoke(myact)
14:52:31.026 (26542000)|SYSTEM_MODE_ENTER|false
14:52:31.026 (26556000)|SYSTEM_METHOD_ENTRY|[13]|System.debug(ANY)
14:52:31.026 (26560000)|ENTERING_MANAGED_PKG|
14:52:31.026 (26580000)|USER_DEBUG|[13]|DEBUG|----------------In Act-------------
14:52:31.026 (26587000)|SYSTEM_METHOD_EXIT|[13]|System.debug(ANY)
14:52:31.026 (26591000)|SYSTEM_MODE_EXIT|false
14:52:31.026 (26619000)|CODE_UNIT_FINISHED|lifecycle invoke(myact)
14:52:31.026 (26638000)|VF_APEX_CALL|j_id4|{!myact}|PageReference: none
14:52:31.039 (39212000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|lifecycle get(s)
14:52:31.039 (39226000)|SYSTEM_MODE_ENTER|true
14:52:31.039 (39236000)|CODE_UNIT_STARTED|[EXTERNAL]|01pU00000016Hc7|s
14:52:31.039 (39273000)|SYSTEM_MODE_ENTER|false
14:52:31.039 (39291000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
14:52:31.039 (39296000)|ENTERING_MANAGED_PKG|
14:52:31.039 (39306000)|USER_DEBUG|[4]|DEBUG|----------------In Get-------------
14:52:31.039 (39314000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
14:52:31.039 (39319000)|SYSTEM_MODE_EXIT|false
14:52:31.039 (39327000)|CODE_UNIT_FINISHED|s
14:52:31.039 (39332000)|CODE_UNIT_FINISHED|lifecycle get(s)
14:52:31.040 (40451000)|VF_SERIALIZE_VIEWSTATE_BEGIN|066U0000000X8Ey
14:52:31.041 (41722000)|VF_SERIALIZE_VIEWSTATE_END
14:52:31.301 (44149000)|CUMULATIVE_LIMIT_USAGE
14:52:31.301|LIMIT_USAGE_FOR_NS|jaggy|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 6 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

This log is only after action button is invoked. I dont know why it is printing '---------------in get----------------' string. Any suggestion on that.

 

 

  • April 17, 2012
  • Like
  • 0

Hi Guys,

 

I am using a custom controller attached to a VF page as follows:

public without sharing class AccountController {

    private final Account account;
    public AccountController() {
    account = [select id, name, site from Account where id =
    :ApexPages.currentPage().getParameters().get('id')];
    }
    public Account getAccount() {
    return account;
    }
    public PageReference save() {
    update account;
    return null;
    }
    
}

 

<apex:page controller="AccountController"> 
    {!account.name}
</apex:page>

 I've a profile Standard Employee which doesnt have read access to account and OWD for account is public read only. Now when i login as standard employee and opens vf page then no account name is displayed. According to me in system mode profile based permissions and FLS is not enforced. So what i am missing here?

  • April 17, 2012
  • Like
  • 0

I wanted to create a trigger that basically copies the first 50 characters of the Comments field in Task to a custom field. It looks kinda like this

 

for (Task tasksToUpdate: trigger.new){
Integer max=tasksToUpdate.Description.length();
if (max != 0) {
Integer endCharacter = 0;
if (max < 50)
endCharacter = max;
else
endCharacter = 50;
tasksToUpdate.Comments_Short__c = tasksToUpdate.Description.substring(0,endCharacter) ;
}
}

All well and good, but when I try to execute this with a blank Comments field, the error "execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object" shows up. I think I'm supposed to have a catch-exception when it is blank/null, but I can't understand why this doesn't work. Any ideas?

Hi,

 

I've written a test method and I've to test the functionality by different users. So I've used System.runAs for that. But it's not working as I expected. Below is my code.

 

        Profile projectManagerProfile = [SELECT Id FROM Profile WHERE Name = 'Project Manager'];
        Profile teamMemberProfile = [SELECT Id FROM Profile WHERE Name = 'Team Member'];        

        User projectManager = new User(alias = 'promgr', 
                                       email = 'pm@aaaa.co.uk', 
                                       emailencodingkey = 'UTF-8', 
                                       lastname = 'Testing', 
                                       languagelocalekey = 'en_US', 
                                       localesidkey = 'en_US', 
                                       profileid = projectManagerProfile.Id, 
                                       timezonesidkey = 'Europe/London', 
                                       username = 'xxxpm.aaa@aa.co.uk');  
        
        User teamMemberRead = new User(alias = 'tmr', 
                                       email = 'team.member.read@precursive.co.uk', 
                                       emailencodingkey = 'UTF-8', 
                                       lastname = 'Testing', 
                                       languagelocalekey = 'en_US', 
                                       localesidkey = 'en_US', 
                                       profileid = teamMemberProfile.Id, 
                                       timezonesidkey = 'Europe/London', 
                                       username = 'xxxteam.member.read@precursive.co.uk');  
        
        User teamMemberWrite = new User(alias = 'tmw', 
                                        email = 'team.member.write@aaa.co.uk', 
                                        emailencodingkey = 'UTF-8', 
                                        lastname = 'Testing', 
                                        languagelocalekey = 'en_US', 
                                        localesidkey = 'en_US', 
                                        profileid = teamMemberProfile.Id, 
                                        timezonesidkey = 'Europe/London', 
                                        username = 'xxxteam.member.write@aaaa.co.uk');  
                                        
        insert new User[]{projectManager, teamMemberRead, teamMemberWrite};     
        
        Project__c project = null;
        Phase__c phase = null;	// default phase of a project
        Team_Member__c teamMember1 = null;
        Team_Member__c teamMember2 = null;
        

        // Login as PM and create a project
        System.runAs(projectManager) {
            project = new Project__c(Name = 'XXX My Dummy Project XXX',                                      
                                                Start_Date__c = System.today(),
                                                End_Date__c = System.today().addYears(1),
                                                Description__c = 'XXX My Dummy Desc XXX');          
            insert project;
            
            // A default phase is always created upon creation of a project.
            // So we don't need to create one seperatley.                                 
            phase = [SELECT Id FROM Phase__c WHERE Name = 'XXX My Dummy Project XXX - Phase 1' and Project__c = :project.Id];   

            teamMember1 = new Team_Member__c(Name = 'XXX My Team Member Read XXX',
                                   			 Project__c = project.Id,
                                   			 Phase__c = phase.Id,
                                   			 User__c = teamMemberRead.Id,
                                   			 Access__c = 'Read');
           
            teamMember2 = new Team_Member__c(Name = 'XXX My Team Member Write XXX',
                                   			 Project__c = project.Id,
                                   			 Phase__c = phase.Id,
                                   			 User__c = teamMemberWrite.Id,
                                   			 Access__c = 'Write');
            
            insert new Team_Member__c[]{teamMember1, teamMember2};
        }
        
        /* Testing begins */
        // Check for both team members,
        // they should have at least "read" access to the phase record.
        
        System.runAs(teamMemberRead) {
            Phase__c ph;
            try {
                ph = Database.query('SELECT Id FROM Phase__c WHERE Id = \'' + phase.Id + '\' and Name = \'XXX My Dummy Project XXX - Phase 1\'');                
            } catch (Exception e) {System.debug('########-' + e);}
            
            System.assertNotEquals(null, ph);
        }

 My assert gets failed. It shows that 'ph' is null. According to me it shouldn't be null. What am I missing here.

  • March 01, 2012
  • Like
  • 0

I am trying to get complete coverage for my test class and cannot get there as I cannot get passed 56%.  Can anyone point me in the right direction?

 

Class

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem {get;set;}
    public ID<Order__c> oid {get;set;}
    public string orderid;
    public integer iqty;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public PageReference saveitems()
    {
        //Save item relationships
        List<Order_Item_Junction__c> insitems = new List<Order_Item_Junction__c>();
        try{
            for(integer i=0;i<lstoitem.size();i++)
                {
                if(lstoitem[i].Quantity__c > 0)
                    {
                    Order_Item_Junction__c qtyitem = new Order_Item_Junction__c();
                    qtyitem.Order__c = oid;
                    qtyitem.Product_Bundle__c = lstbundle[i].Id;
                    qtyitem.Quantity__c = lstoitem[i].Quantity__c;
                    insitems.add(qtyitem);
                    }
                }
            if(insitems.size()>0)
                insert insitems;
        }catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
        return null; 
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        
            if(orecordtype == 'New Order')
            {            
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        lstoitem = new List<Order_Item_Junction__c>();
        oid = orderid;
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = oid;
            oitem.Quantity__c = 0;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 

 

Page

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script language="JavaScript" type="text/javascript">
function CloseAndRefresh()
{
    window.opener.location.href="/{!$CurrentPage.parameters.oid}";
    window.top.close();
      
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headerValue="Order" value="{!l.Order__c}" width="40%"/>
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="40%"/>
                        <apex:column headerValue="Quantity" id="iqty" width="20%">
                            <apex:inputField value="{!l.Quantity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Test Class

@isTest
private class oitemControllerTest
{
    static testmethod void testorderNew1()
    {
        delete [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];

        RecordType recnew = [select ID, Name from RecordType where Name = 'New Order' and SObjectType = 'Order__c'];
        RecordType recreturn = [select ID, Name from RecordType where Name = 'Return Order' and SObjectType = 'Order__c'];
        
        Order__c order1 = new Order__c(recordtypeid=recnew.Id);
        insert order1;
        
        Order__c order2 = new Order__c(recordtypeid=recreturn.Id);
        insert order2;
        
        RecordType recopen = [select ID, Name from RecordType where Name = 'Open' and SObjectType = 'Product_Bundle__c'];
        RecordType recreturnbun = [select ID, Name from RecordType where Name = 'Open' and SObjectType = 'Product_Bundle__c'];
        
        Product_Bundle__c bundle1 = new Product_Bundle__c(recordtypeid = recopen.id, Name = 'TestBundle1', Description__c = 'Testing1', Completed__c = TRUE, Order_Availability__c = 'New Order');
        Product_Bundle__c bundle2 = new Product_Bundle__c(recordtypeid = recreturnbun.id, Name = 'TestBundle2', Description__c = 'Testing2', Completed__c = TRUE, Order_Availability__c = 'Return Order');
        Product_Bundle__c bundle3 = new Product_Bundle__c(recordtypeid = recopen.id, Name = 'TestBundle3', Description__c = 'Testing3', Completed__c = FALSE, Order_Availability__c = 'New Order');
        Product_Bundle__c bundle4 = new Product_Bundle__c(recordtypeid = recreturnbun.id, Name = 'TestBundle1', Description__c = 'Testing4', Completed__c = FALSE, Order_Availability__c = 'Return Order');
        Product_Bundle__c [] bundle_array = new Product_Bundle__c []{bundle1,bundle2,bundle3,bundle4};
        insert bundle_array;
        
        Order_Item_Junction__c oi1 = new Order_Item_Junction__c(Order__c = order1.Id,Product_Bundle__c = bundle1.id, Quantity__c = 1);
        Order_Item_Junction__c oi2 = new Order_Item_Junction__c(Order__c = order1.Id,Product_Bundle__c = bundle2.id, Quantity__c = 2);
        Order_Item_Junction__c oi3 = new Order_Item_Junction__c(Order__c = order2.Id,Product_Bundle__c = bundle3.id, Quantity__c = 1);
        Order_Item_Junction__c oi4 = new Order_Item_Junction__c(Order__c = order2.Id,Product_Bundle__c = bundle4.id, Quantity__c = 2);        
        Order_Item_Junction__c [] oi_array = new Order_Item_Junction__c []{oi1,oi2};
        insert oi_array;
        
        PageReference pref1 = Page.orderpage;
        pref1.getParameters().put('oid',order1.Id);
        pref1.getParameters().put('orecordtype',recnew.Name);
        Test.setCurrentPage(pref1);
        
        ApexPages.StandardController stdcon1 = new ApexPages.StandardController(oi_array[0]);
        oitemController oicon1 = new oitemController(stdcon1);
        oicon1.setproceed();
        oicon1.saveitems();

        PageReference pref2 = Page.orderpage;
        pref2.getParameters().put('oid',order2.Id);
        pref2.getParameters().put('orecordtype',recreturn.Name);
        pref2.getParameters().put('orecordtype',recreturn.Name);
        Test.setCurrentPage(pref2);
        
        ApexPages.StandardController stdcon2 = new ApexPages.StandardController(oi_array[5]);
        oitemController oicon2 = new oitemController(stdcon2);
        oicon1.setproceed();
        oicon1.saveitems();
            
    }
}

 

 

  • March 01, 2012
  • Like
  • 0

Hi,

 

I'm using following trigger for sharing records to hiring manager via apex

 

trigger Hiring_Manager_Job_Share on Position__c (after insert) {

    // We only execute the trigger after a Job record has been inserted 
    // because we need the Id of the Job record to already exist.
    if(trigger.isInsert){
     
    // Job_Share is the "Share" table that was created when the
    // Organization Wide Default sharing setting was set to "Private".
    // Allocate storage for a list of Position__Share records.
    List<Position__Share> jobShares  = new List<Position__Share>();

    // For each of the Job records being inserted, do the following:
    for(Position__c job : trigger.new){

        // Create a new Position__Share record to be inserted in to the Job_Share table.
        Position__Share hiringManagerShare = new Position__Share();
            
        // Populate the Position__Share record with the ID of the record to be shared.
        hiringManagerShare.ParentId = job.Id;
            
        // Then, set the ID of user or group being granted access. In this case,
        // we’re setting the Id of the Hiring Manager that was specified by 
        // the Recruiter in the Hiring_Manager__c lookup field on the Job record.  
        // (See Image 1 to review the Job object's schema.)
        hiringManagerShare.UserOrGroupId = job.Hiring_Manager__c;
            
        // Specify that the Hiring Manager should have edit access for 
        // this particular Job record.
        hiringManagerShare.AccessLevel = 'read';
            
        // Specify that the reason the Hiring Manager can edit the record is 
        // because he’s the Hiring Manager.
        // (Hiring_Manager_Access__c is the Apex Sharing Reason that we defined earlier.)
        hiringManagerShare.RowCause = Schema.Position__Share.RowCause.Hiring_Manager_Access__c;
            
        // Add the new Share record to the list of new Share records.
        jobShares.add(hiringManagerShare);
    }
        
    // Insert all of the newly created Share records and capture save result 
    insert jobShares;
        
    // Error handling code omitted for readability.
    }
}

 

and OWD for Position__c is Publice Read Only.

 

Now, when I create a new position record I get this error

Apex trigger Hiring_Manager_Job_Share caused an unexpected exception, contact your administrator: Hiring_Manager_Job_Share: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: AccessLevel (trivial share level Read, for organization with default level Read): [AccessLevel]: Trigger.Hiring_Manager_Job_Share: line 41, column 1

 

I can understand that this is trivial case and can be passed why my code is not working? What I am missing here?

  • February 24, 2012
  • Like
  • 0

Hi,

 

In apex, How can we determine OWD setting (Org Wide Defaults) for a particular object if we already know object name?

 

 

 

  • February 24, 2012
  • Like
  • 0

Hi All,

 

Suppose I create one page using visualforce . Will  that page work for all the mobiles  or do I need to pass some 

parameters which is defined by Salesforce for creating mobile app .

 

I dont want to create mobile app .however , wanted to access the same page from diff

mobile device .will it create any issue ?

 

Regards,

Neha

I am new to salesforce product. I am developing an application using Sencha Touch. I see a lot of references using VisualForce and Apex tools to developer pages interacting with database.
 

Is it possible to use ajax toolkit from sencha touch app?

I tried to use the connection.js library, but i am not able to login and i didn't see any documentation or tutorial on how to make this happen on sencha app or just html 5 app, unless it is iOs or Android app.

i've made reference to


http://na7.salesforce.com/soap/ajax/21.0/connection.js

 


i am wondering i need to add the token to the password

 

Can someone provide me with an example for sencha or html 5

 

Thanks

hi ,

 

I am quite new to salesforce and i am trying to create mobile appliction that uses html5 geolocation facility .

i am succedded in getting the lattitude and longitude information of the device from which the app is called. but unable to locate that device position in google map by providing its lattitude and longitude position .

 

also i wanna to use the reverse geocoding feature of google map i.e to display appropriate address of the device by providing its lattitude and longitude information.

 

can anyone help me in this scenario.

 

There have been a few posts about making fields show as required (little red bar):
* http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=2419
* http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=1254

in which SF folks say that in order to make the bar appear, just use an inputField element, and make the field required in your field definitions.

Fair enough, that seems to work most of the time.

However, in my current project I've got a custom object, and the Name field is included on a VF page.  And I'm using an inputField element, but it's not showing the red bar.  And moreover, if I leave the field blank, it gets filled in somehow with the ID of the record, rather than throwing an error.

I thought Name fields were required by definition.  If I edit the record in the standard layout, I get the red bar and leaving the Name blank throws an error.

I'm using the standard controller (with an extension).  Is this a bug?

Thanks much!
  • August 12, 2008
  • Like
  • 1