0
public with sharing class Apparel_PageController { public List<Trendsters_Order__c> orders{get;set;} public String contactId{get;set;} public Case objCase{get;set;} public Decimal totalAmount{get;set;} public Decimal cartSize{get;set;} public String currentProductId{get;set;} public List<Trendsterz_Inventory__c> inventries {get;set;} public List<Trendsters_Order__c> cart{get;set;} public Apparel_PageController(){ totalAmount = 0; cartSize = 0; cart = new List<Trendsters_Order__c>(); User objUser = [select ContactId from User where Id = :UserInfo.getUserId()]; contactId = objUser.ContactId; //contactId = '0037F00000a8HVg'; objCase = new Case(ContactId=contactId); inventries = [select Id,Brand__c, Designer_Name__c, Design_Name__c, Price__c,Image_Url__c from Trendsterz_Inventory__c LIMIT 10]; } public void fetchOrders(){ orders = [SELECT Id,Name,Brand__c,Contact__c,Contact__r.Name, Contact__r.Email, Designer_Name__c,Design_Name__c,Email__c,Price__c,Order_Status__c FROM Trendsters_Order__c WHERE Contact__c = :contactId]; } public void submitFeedback(){ insert objCase; } public void addToCart(){ for(Trendsterz_Inventory__c inventry : inventries){ if(currentProductId !=null && inventry.Id == currentProductId){ Trendsters_Order__c order = new Trendsters_Order__c(); system.debug('contactid -->'+contactId); order.Contact__c = contactId; order.Design_Name__c = inventry.Design_Name__c; order.Price__c= inventry.Price__c; cart.add(order); break; } } cartSize = cart.size(); // totalAmount = cart.size(); } public void payProduct(){ system.debug('cart -> ' + cart.size()); insert cart; } } 
5
  • Error is preity clear. Contact is required and blank. Are you facing any challenge. Commented May 12, 2018 at 7:58
  • In my system debug....it is fetching Contact ID.... Commented May 12, 2018 at 8:06
  • After sometime it showed success.....it was happening yesterday also.....it failed and then after sometime automatically it got success Commented May 12, 2018 at 8:10
  • You are getting ContactId always. Commented May 12, 2018 at 8:22
  • M really new on this....it's just been 1 week that I have started working on salesforce.....can u please explain...what could the error be?.....coz exactly as u said Contact Id is getting fetched...but then y Required field Missing error is coming? Commented May 12, 2018 at 8:28

1 Answer 1

2

One possibility to consider is that you are checking the code using different logins (users).

The User.ContactId is populated for user's that have setup their login via Self-Registration for Your Community because that mechanism starts from a Contact and hooks up a User to that Contact. But it is not populated for users that have a standard login created by a System Administrator.

If that is the case, your page should just output a message such as "Only community users can use this page". Or the page logic should be otherwise reconsidered for that case.

4
  • Thanku so much....but it is from a registered user. Commented May 12, 2018 at 10:30
  • @SaniyaVirmani Ah OK. One other thing to check is that there are no triggers or workflows on Trendsters_Order__c that are resetting the ContactId. Commented May 12, 2018 at 10:32
  • nop....@Keith C....there are no triggers and workflows Commented May 12, 2018 at 11:04
  • @KeithC Hi there! I've had this issue where I get the required field missing error on a specific field on a custom object. This field was deployed as a required field but was changes to not being required after a day. However, we're still getting this error once in a while on new records being inserted. I haven't been able to find out why this is happening. Please help if you have ideas as to what may be causing this. Thanks! Commented Sep 17, 2020 at 20:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.